Merge branch 'develop' of https://gitee.com/xlljc/DungeonShooting into develop

This commit is contained in:
王晗智 2024-03-17 22:42:38 +08:00
commit f006bccf3a
59 changed files with 811 additions and 446 deletions

View File

@ -13,122 +13,10 @@ namespace Generator;
/// </summary>
public static class BuffGenerator
{
private const string SavePath = "src/game/manager/BuffRegister.cs";
public static bool Generate()
{
try
{
var str = "";
var buffInfos = new Dictionary<string, BuffInfo>();
var types = typeof(BuffGenerator).Assembly.GetTypes();
//包含[BuffAttribute]特性
var enumerable = types.Where(type =>
type.IsClass && !type.IsAbstract && type.IsAssignableTo(typeof(BuffFragment)));
foreach (var type in enumerable)
{
var attribute = (BuffAttribute)type.GetCustomAttribute(typeof(BuffAttribute), false);
if (attribute != null)
{
if (buffInfos.ContainsKey(attribute.BuffName))
{
GD.PrintErr($"Buff '{attribute.BuffName}' 重名!");
return false;
}
var buffInfo = new BuffInfo(attribute.BuffName, attribute.Description, type);
str += $"{buffInfo.Name}: {buffInfo.Description}\n";
buffInfos.Add(attribute.BuffName, buffInfo);
//判断重写参数情况
//1参数
var methodInfo1 = type.GetMethod(nameof(BuffFragment.InitParam),
BindingFlags.Instance | BindingFlags.Public, new Type[] { typeof(float) });
if (methodInfo1 != null &&
methodInfo1.GetBaseDefinition().DeclaringType != methodInfo1.DeclaringType)
{
buffInfo.Params.Add(1);
}
//2参数
var methodInfo2 = type.GetMethod(nameof(BuffFragment.InitParam),
BindingFlags.Instance | BindingFlags.Public, new Type[] { typeof(float), typeof(float) });
if (methodInfo2 != null &&
methodInfo2.GetBaseDefinition().DeclaringType != methodInfo2.DeclaringType)
{
buffInfo.Params.Add(2);
}
//3参数
var methodInfo3 = type.GetMethod(nameof(BuffFragment.InitParam),
BindingFlags.Instance | BindingFlags.Public,
new Type[] { typeof(float), typeof(float), typeof(float) });
if (methodInfo3 != null &&
methodInfo3.GetBaseDefinition().DeclaringType != methodInfo3.DeclaringType)
{
buffInfo.Params.Add(3);
}
//4参数
var methodInfo4 = type.GetMethod(nameof(BuffFragment.InitParam),
BindingFlags.Instance | BindingFlags.Public,
new Type[] { typeof(float), typeof(float), typeof(float), typeof(float) });
if (methodInfo4 != null &&
methodInfo4.GetBaseDefinition().DeclaringType != methodInfo4.DeclaringType)
{
buffInfo.Params.Add(4);
}
}
}
GenerateCode(buffInfos);
GD.Print("-----------------------------");
GD.Print(str);
}
catch (Exception e)
{
GD.PrintErr(e.Message + "\n" + e.StackTrace);
return false;
}
return true;
}
private static void GenerateCode(Dictionary<string, BuffInfo> buffInfo)
{
var str = "";
foreach (var kv in buffInfo)
{
var info = kv.Value;
var s = "";
for (var i = 0; i < info.Params.Count; i++)
{
if (i > 0) s += ", ";
s += info.Params[i];
}
str += $" BuffInfos.Add(\"{info.Name}\", new BuffInfo(\"{info.Name}\", null, new List<int>() {{ {s} }}, typeof({info.Type.FullName})));\n";
}
var code = $"using System.Collections.Generic;\n" +
$"/// <summary>\n" +
$"/// buff 注册类, 调用 Init() 函数初始化数据\n" +
$"/// 注意: 该类为 Tools 面板下自动生成的, 请不要手动编辑!\n" +
$"/// </summary>\n" +
$"public class BuffRegister\n" +
$"{{\n" +
$" /// <summary>\n" +
$" /// 所有 buff 信息\n" +
$" /// </summary>\n" +
$" public static Dictionary<string, BuffInfo> BuffInfos {{ get; private set; }}\n" +
$" /// <summary>\n" +
$" /// 初始化 buff\n" +
$" /// </summary>\n" +
$" public static void Init()\n" +
$" {{\n" +
$" BuffInfos = new Dictionary<string, BuffInfo>();\n" +
str +
$" }}\n" +
$"}}";
File.WriteAllText(SavePath, code);
}
}
#endif

View File

@ -1,12 +1,11 @@
[gd_scene load_steps=7 format=3 uid="uid://crwflnrd6so2i"]
[gd_scene load_steps=6 format=3 uid="uid://drjkrimgii1u0"]
[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="1_f18nu"]
[ext_resource type="Script" path="res://src/game/activity/prop/active/ActiveProp5000.cs" id="1_nkhdg"]
[ext_resource type="SpriteFrames" uid="uid://cvosq47nbdnus" path="res://resource/spriteFrames/prop/active/ActiveProp5000.tres" id="3_4xrrj"]
[ext_resource type="Script" path="res://src/game/activity/prop/ActiveProp.cs" id="1_n541c"]
[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="2_75di4"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mrkt4"]
resource_local_to_scene = true
shader = ExtResource("1_f18nu")
shader = ExtResource("2_75di4")
shader_parameter/blend = Color(0, 0, 0, 0.470588)
shader_parameter/schedule = 1.0
shader_parameter/modulate = Color(1, 1, 1, 1)
@ -18,7 +17,7 @@ shader_parameter/grey = 0.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b6ii6"]
resource_local_to_scene = true
shader = ExtResource("1_f18nu")
shader = ExtResource("2_75di4")
shader_parameter/blend = Color(1, 1, 1, 1)
shader_parameter/schedule = 0.0
shader_parameter/modulate = Color(1, 1, 1, 1)
@ -31,9 +30,9 @@ shader_parameter/grey = 0.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cpqup"]
size = Vector2(12, 10)
[node name="ActiveProp5000" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
[node name="ActiveProp" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 4
script = ExtResource("1_nkhdg")
script = ExtResource("1_n541c")
ShadowSprite = NodePath("ShadowSprite")
AnimatedSprite = NodePath("AnimatedSprite")
Collision = NodePath("Collision")
@ -44,7 +43,6 @@ material = SubResource("ShaderMaterial_mrkt4")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_b6ii6")
sprite_frames = ExtResource("3_4xrrj")
[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_cpqup")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=3 uid="uid://dfpic4nubu7cf"]
[gd_scene load_steps=6 format=3 uid="uid://dfpic4nubu7cf"]
[ext_resource type="Script" path="res://src/game/activity/prop/BuffProp.cs" id="1_nlcp6"]
[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="2_imicp"]
@ -27,9 +27,6 @@ shader_parameter/outline_rainbow = false
shader_parameter/outline_use_blend = true
shader_parameter/grey = 0.0
[sub_resource type="SpriteFrames" id="SpriteFrames_y5dlc"]
resource_local_to_scene = true
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cpqup"]
size = Vector2(12, 10)
@ -46,7 +43,6 @@ material = SubResource("ShaderMaterial_mrkt4")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_b6ii6")
sprite_frames = SubResource("SpriteFrames_y5dlc")
[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_cpqup")

View File

@ -1,50 +0,0 @@
[gd_scene load_steps=7 format=3 uid="uid://dlf83ph0msl2l"]
[ext_resource type="Script" path="res://src/game/activity/prop/active/ActiveProp5001.cs" id="1_klvlf"]
[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="2_2cgdl"]
[ext_resource type="SpriteFrames" uid="uid://bbjyakayescy5" path="res://resource/spriteFrames/prop/active/ActiveProp5001.tres" id="3_fagk1"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mrkt4"]
resource_local_to_scene = true
shader = ExtResource("2_2cgdl")
shader_parameter/blend = Color(0, 0, 0, 0.470588)
shader_parameter/schedule = 1.0
shader_parameter/modulate = Color(1, 1, 1, 1)
shader_parameter/show_outline = false
shader_parameter/outline_color = Color(0, 0, 0, 1)
shader_parameter/outline_rainbow = false
shader_parameter/outline_use_blend = true
shader_parameter/grey = 0.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b6ii6"]
resource_local_to_scene = true
shader = ExtResource("2_2cgdl")
shader_parameter/blend = Color(1, 1, 1, 1)
shader_parameter/schedule = 0.0
shader_parameter/modulate = Color(1, 1, 1, 1)
shader_parameter/show_outline = true
shader_parameter/outline_color = Color(0, 0, 0, 1)
shader_parameter/outline_rainbow = false
shader_parameter/outline_use_blend = true
shader_parameter/grey = 0.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cpqup"]
size = Vector2(12, 10)
[node name="ActiveProp5001" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 4
script = ExtResource("1_klvlf")
ShadowSprite = NodePath("ShadowSprite")
AnimatedSprite = NodePath("AnimatedSprite")
Collision = NodePath("Collision")
[node name="ShadowSprite" type="Sprite2D" parent="."]
z_index = -1
material = SubResource("ShaderMaterial_mrkt4")
[node name="AnimatedSprite" type="AnimatedSprite2D" parent="."]
material = SubResource("ShaderMaterial_b6ii6")
sprite_frames = ExtResource("3_fagk1")
[node name="Collision" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_cpqup")

View File

@ -1 +1,38 @@
[]
[
{
"Id": "0001",
"Remark": "\u533B\u836F\u7BB1",
"__Activity": "prop5000",
"Buff": null,
"Condition": {
"HpFull": [
0
]
},
"Effect": {
"Hp": [
2
]
},
"CooldownTime": 0,
"IsConsumables": true,
"MaxCount": 10
},
{
"Id": "0002",
"Remark": "\u5F39\u836F\u7BB1",
"__Activity": "prop5001",
"Buff": null,
"Condition": {
"AmmoFull": [
0
]
},
"Effect": {
"TotalAmmo": []
},
"CooldownTime": 0,
"IsConsumables": true,
"MaxCount": 10
}
]

View File

@ -653,7 +653,7 @@
"Details": "",
"IsStatic": false,
"__Material": "",
"Prefab": "res://prefab/prop/active/ActiveProp5000.tscn",
"Prefab": "res://prefab/prop/ActiveProp.tscn",
"Icon": "res://resource/sprite/prop/active/ActiveProp5000.png",
"ShowInMapEditor": true
},
@ -667,7 +667,7 @@
"Details": "",
"IsStatic": false,
"__Material": "",
"Prefab": "res://prefab/prop/active/ActiveProp5001.tscn",
"Prefab": "res://prefab/prop/ActiveProp.tscn",
"Icon": "res://resource/sprite/prop/active/ActiveProp5001.png",
"ShowInMapEditor": true
},

View File

@ -44,7 +44,7 @@
"Remark": "\u6740\u4F24\u5F39",
"__Activity": "prop0005",
"Buff": {
"Damage": [
"BulletDamage": [
2,
0.2
]
@ -108,7 +108,7 @@
-8,
8
],
"Damage": [
"BulletDamage": [
2,
-0.35
],

View File

@ -49,7 +49,7 @@
"RewardList": [
{
"ErrorType": 0,
"Path": "resource/map/tileMaps/Test1/reward/Award1"
"Path": "resource/map/tileMaps/Test1/reward/Reward1"
}
],
"ShopList": [

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
[{"Name":"Preinstall1","Weight":100,"Remark":"","AutoFill":true,"WaveList":[[]]}]

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cugykjrqe8wil"
path="res://.godot/imported/Preview.png-d591ad3d03347a3f1bfee6cb6974156c.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resource/map/tileMaps/Test1/reward/Reward1/Preview.png"
dest_files=["res://.godot/imported/Preview.png-d591ad3d03347a3f1bfee6cb6974156c.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View File

@ -0,0 +1 @@
{"Position":{"X":-2,"Y":-5},"Size":{"X":10,"Y":11},"DoorAreaInfos":[],"GroupName":"Test1","RoomType":16,"RoomName":"Reward1","Weight":100,"Remark":""}

View File

@ -0,0 +1 @@
{"NavigationVertices":[{"X":90,"Y":74},{"X":6,"Y":74},{"X":6,"Y":-26},{"X":90,"Y":-26}],"NavigationPolygon":[[0,1,2,3]],"Floor":[0,-2,0,3,0,-1,0,3,0,0,0,3,0,1,0,3,0,2,0,3,0,3,0,3,1,-2,0,3,1,-1,0,3,1,0,0,3,1,1,0,3,1,2,0,3,1,3,0,3,2,-2,0,3,2,-1,0,3,2,0,0,3,2,1,0,3,2,2,0,3,2,3,0,3,3,-2,0,3,3,-1,0,3,3,0,0,3,3,1,0,3,3,2,0,3,3,3,0,3,4,-2,0,3,4,-1,0,3,4,0,0,3,4,1,0,3,4,2,0,3,4,3,0,3,5,-2,0,3,5,-1,0,3,5,0,0,3,5,1,0,3,5,2,0,3,5,3,0,3],"CustomFloor1":[1,-2,2,2,6,1,-1,2,4,8,0,-1,2,1,7,0,-2,2,1,6,1,0,2,3,7,0,0,2,1,7,1,1,2,3,7,0,1,2,1,7,1,2,2,4,9,0,2,2,1,7,1,3,2,2,8,0,3,2,1,8,2,2,2,2,6,2,3,2,2,8,3,2,2,2,6,3,3,2,2,8,4,2,2,5,9,4,3,2,2,8,5,2,2,3,7,5,3,2,3,8,5,1,2,3,7,4,1,2,1,7,5,0,2,3,7,4,0,2,1,7,5,-1,2,3,7,4,-1,2,5,8,5,-2,2,3,6,4,-2,2,2,6,3,-1,2,2,8,3,-2,2,2,6,2,-1,2,2,8,2,-2,2,2,6],"CustomFloor2":[],"CustomFloor3":[],"CustomMiddle1":[],"CustomMiddle2":[],"CustomTop":[]}

View File

@ -1,14 +0,0 @@
[gd_resource type="SpriteFrames" load_steps=2 format=3 uid="uid://cvosq47nbdnus"]
[ext_resource type="Texture2D" uid="uid://cu0wlvrbntvyd" path="res://resource/sprite/prop/active/ActiveProp5000.png" id="1_mkqgb"]
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_mkqgb")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]

View File

@ -1,14 +0,0 @@
[gd_resource type="SpriteFrames" load_steps=2 format=3 uid="uid://bbjyakayescy5"]
[ext_resource type="Texture2D" uid="uid://fby848tbodc" path="res://resource/sprite/prop/active/ActiveProp5001.png" id="1_1xlxo"]
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_1xlxo")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]

View File

@ -34,13 +34,36 @@ public static partial class ExcelConfig
public Dictionary<string, float[]> Buff;
/// <summary>
/// 使用完成后是否自动销毁
/// 道具使用条件 <br/>
/// 参数配置方式与buff字段相同 <br/>
/// 性名称请参阅condition属性表
/// </summary>
[JsonInclude]
public bool AutoDestroy;
public Dictionary<string, float[]> Condition;
/// <summary>
/// 最大叠加次数
/// 道具使用效果 <br/>
/// 参数配置方式与buff字段相同 <br/>
/// 性名称请参阅effect属性表
/// </summary>
[JsonInclude]
public Dictionary<string, float[]> Effect;
/// <summary>
/// 使用一次后的冷却时间 <br/>
/// 单位: 秒
/// </summary>
[JsonInclude]
public float CooldownTime;
/// <summary>
/// 是否是消耗品, 如果为true, 则每次使用都会消耗叠加数量
/// </summary>
[JsonInclude]
public bool IsConsumables;
/// <summary>
/// 最大叠加次数, 仅当IsConsumables为true时有效
/// </summary>
[JsonInclude]
public uint MaxCount;
@ -55,7 +78,10 @@ public static partial class ExcelConfig
inst.Remark = Remark;
inst.Activity = Activity;
inst.Buff = Buff;
inst.AutoDestroy = AutoDestroy;
inst.Condition = Condition;
inst.Effect = Effect;
inst.CooldownTime = CooldownTime;
inst.IsConsumables = IsConsumables;
inst.MaxCount = MaxCount;
return inst;
}

View File

@ -91,7 +91,7 @@ public partial class GameApplication : Node2D, ICoroutine
//初始化配置表
ExcelConfig.Init();
PreinstallMarkManager.Init();
BuffRegister.Init();
PropFragmentRegister.Init();
//初始化房间配置数据
InitRoomConfig();
//初始化TileSet配置数据
@ -102,6 +102,8 @@ public partial class GameApplication : Node2D, ICoroutine
Enemy.InitEnemyAttribute();
//初始化buff数据
BuffProp.InitBuffAttribute();
//初始化主动道具数据
ActiveProp.InitActiveAttribute();
DungeonConfig = new DungeonConfig();
DungeonConfig.GroupName = "Test1";

View File

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using Config;
using Godot;
/// <summary>
@ -8,6 +10,11 @@ using Godot;
[Tool]
public partial class ActiveProp : PropActivity, IPackageItem<Role>
{
/// <summary>
/// 配置数据
/// </summary>
public ExcelConfig.ActivePropBase Attribute { get; private set; }
public int PackageIndex { get; set; }
/// <summary>
@ -52,17 +59,7 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
}
private int _maxCount = 1;
/// <summary>
/// 使用一次后的冷却时间, 单位: 秒
/// </summary>
public float CooldownTime { get; set; } = 2f;
/// <summary>
/// 当道具使用完后是否自动销毁
/// </summary>
public bool AutoDestroy { get; set; } = false;
/// <summary>
/// 道具充能进度, 必须要充能完成才能使用, 值范围: 0 - 1
/// </summary>
@ -89,21 +86,192 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
//冷却计时器
private float _cooldownTimer = 0;
//被动属性
private readonly List<BuffFragment> _buffFragment = new List<BuffFragment>();
//条件
private readonly List<ConditionFragment> _conditionFragment = new List<ConditionFragment>();
//效果
private readonly List<EffectFragment> _effectFragment = new List<EffectFragment>();
public override void OnInit()
{
base.OnInit();
var buffAttribute = GetActiveAttribute(ActivityBase.Id);
Attribute = buffAttribute;
//初始化buff属性
if (buffAttribute.Buff != null)
{
foreach (var keyValuePair in buffAttribute.Buff)
{
var buffInfo = PropFragmentRegister.BuffFragmentInfos[keyValuePair.Key];
var item = keyValuePair.Value;
switch (item.Length)
{
case 0:
{
var buff = (BuffFragment)AddComponent(buffInfo.Type);
_buffFragment.Add(buff);
}
break;
case 1:
{
var buff = (BuffFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0]);
_buffFragment.Add(buff);
}
break;
case 2:
{
var buff = (BuffFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1]);
_buffFragment.Add(buff);
}
break;
case 3:
{
var buff = (BuffFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2]);
_buffFragment.Add(buff);
}
break;
case 4:
{
var buff = (BuffFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2], item[3]);
_buffFragment.Add(buff);
}
break;
}
}
}
//初始化条件属性
if (buffAttribute.Condition != null)
{
foreach (var keyValuePair in buffAttribute.Condition)
{
var buffInfo = PropFragmentRegister.ConditionFragmentInfos[keyValuePair.Key];
var item = keyValuePair.Value;
switch (item.Length)
{
case 0:
{
var buff = (ConditionFragment)AddComponent(buffInfo.Type);
_conditionFragment.Add(buff);
}
break;
case 1:
{
var buff = (ConditionFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0]);
_conditionFragment.Add(buff);
}
break;
case 2:
{
var buff = (ConditionFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1]);
_conditionFragment.Add(buff);
}
break;
case 3:
{
var buff = (ConditionFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2]);
_conditionFragment.Add(buff);
}
break;
case 4:
{
var buff = (ConditionFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2], item[3]);
_conditionFragment.Add(buff);
}
break;
}
}
}
//初始化效果属性
if (buffAttribute.Effect != null)
{
foreach (var keyValuePair in buffAttribute.Effect)
{
var buffInfo = PropFragmentRegister.EffectFragmentInfos[keyValuePair.Key];
var item = keyValuePair.Value;
switch (item.Length)
{
case 0:
{
var buff = (EffectFragment)AddComponent(buffInfo.Type);
_effectFragment.Add(buff);
}
break;
case 1:
{
var buff = (EffectFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0]);
_effectFragment.Add(buff);
}
break;
case 2:
{
var buff = (EffectFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1]);
_effectFragment.Add(buff);
}
break;
case 3:
{
var buff = (EffectFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2]);
_effectFragment.Add(buff);
}
break;
case 4:
{
var buff = (EffectFragment)AddComponent(buffInfo.Type);
buff.InitParam(item[0], item[1], item[2], item[3]);
_effectFragment.Add(buff);
}
break;
}
}
}
//显示纹理
if (!string.IsNullOrEmpty(ActivityBase.Icon))
{
SetDefaultTexture(ResourceManager.LoadTexture2D(ActivityBase.Icon));
}
MaxCount = (int)Attribute.MaxCount;
}
/// <summary>
/// 当检测是否可以使用时调用
/// </summary>
public virtual bool OnCheckUse()
{
foreach (var fragment in _conditionFragment)
{
if (!fragment.OnCheckUse()) return false;
}
return true;
}
/// <summary>
/// 当道具被使用时调用, 函数返回值为消耗数量
/// 当道具被使用时调用
/// </summary>
protected virtual int OnUse()
protected virtual void OnUse()
{
return 1;
foreach (var fragment in _effectFragment)
{
fragment.OnUse();
}
}
/// <summary>
@ -173,7 +341,7 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
//检测是否达到自动销毁的条件
private bool CheckAutoDestroy()
{
if (Count == 0 && AutoDestroy) //用光了, 自动销毁
if (Count == 0 && Attribute.IsConsumables) //用光了, 自动销毁
{
if (Master != null)
{
@ -205,14 +373,14 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
}
if (CheckUse()) //可以使用道具
{
var num = OnUse();
if (num != 0)
OnUse();
if (Attribute.IsConsumables)
{
Count -= num;
Count -= 1;
}
//冷却计时器
_cooldownTimer = CooldownTime;
_cooldownTimer = Attribute.CooldownTime;
}
}
@ -226,7 +394,7 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
return 1;
}
return (CooldownTime - _cooldownTimer) / CooldownTime;
return (Attribute.CooldownTime - _cooldownTimer) / Attribute.CooldownTime;
}
public override void Interactive(ActivityObject master)
@ -309,10 +477,18 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
public override void OnPickUpItem()
{
foreach (var buffFragment in _buffFragment)
{
buffFragment.OnPickUpItem();
}
}
public override void OnRemoveItem()
{
foreach (var buffFragment in _buffFragment)
{
buffFragment.OnRemoveItem();
}
}
public virtual void OnActiveItem()
@ -327,4 +503,119 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
{
Master.ThrowActiveProp(PackageIndex);
}
/// <summary>
/// 添加被动属性
/// </summary>
public void AddBuffFragment<T>() where T : BuffFragment, new()
{
var fragment = AddComponent<T>();
_buffFragment.Add(fragment);
if (Master != null)
{
fragment.OnPickUpItem();
}
}
/// <summary>
/// 添加被动属性
/// </summary>
public void AddBuffFragment<T>(float arg1) where T : BuffFragment, new()
{
var fragment = AddComponent<T>();
_buffFragment.Add(fragment);
fragment.InitParam(arg1);
if (Master != null)
{
fragment.OnPickUpItem();
}
}
/// <summary>
/// 添加被动属性
/// </summary>
public void AddBuffFragment<T>(float arg1, float arg2) where T : BuffFragment, new()
{
var fragment = AddComponent<T>();
_buffFragment.Add(fragment);
fragment.InitParam(arg1, arg2);
if (Master != null)
{
fragment.OnPickUpItem();
}
}
/// <summary>
/// 添加被动属性
/// </summary>
public void AddBuffFragment<T>(float arg1, float arg2, float arg3) where T : BuffFragment, new()
{
var fragment = AddComponent<T>();
_buffFragment.Add(fragment);
fragment.InitParam(arg1, arg2, arg3);
if (Master != null)
{
fragment.OnPickUpItem();
}
}
/// <summary>
/// 添加被动属性
/// </summary>
public void AddBuffFragment<T>(float arg1, float arg2, float arg3, float arg4) where T : BuffFragment, new()
{
var fragment = AddComponent<T>();
_buffFragment.Add(fragment);
fragment.InitParam(arg1, arg2, arg3, arg4);
if (Master != null)
{
fragment.OnPickUpItem();
}
}
private static bool _init = false;
private static Dictionary<string, ExcelConfig.ActivePropBase> _activeAttributeMap =
new Dictionary<string, ExcelConfig.ActivePropBase>();
/// <summary>
/// 初始化主动道具属性数据
/// </summary>
public static void InitActiveAttribute()
{
if (_init)
{
return;
}
_init = true;
foreach (var buffAttr in ExcelConfig.ActivePropBase_List)
{
if (buffAttr.Activity != null)
{
if (!_activeAttributeMap.TryAdd(buffAttr.Activity.Id, buffAttr))
{
Debug.LogError("发现重复注册的主动道具属性: " + buffAttr.Id);
}
}
}
}
/// <summary>
/// 根据 ActivityBase.Id 获取对应主动道具的属性数据
/// </summary>
public static ExcelConfig.ActivePropBase GetActiveAttribute(string itemId)
{
if (itemId == null)
{
return null;
}
if (_activeAttributeMap.TryGetValue(itemId, out var attr))
{
return attr;
}
throw new Exception($"主动道具'{itemId}'没有在 ActivePropBase 表中配置属性数据!");
}
}

View File

@ -10,6 +10,11 @@ using Godot;
[Tool]
public partial class BuffProp : PropActivity
{
/// <summary>
/// 配置数据
/// </summary>
public ExcelConfig.BuffPropBase Attribute { get; private set; }
//被动属性
private readonly List<BuffFragment> _buffFragment = new List<BuffFragment>();
@ -17,12 +22,13 @@ public partial class BuffProp : PropActivity
{
base.OnInit();
var buffAttribute = GetBuffAttribute(ActivityBase.Id);
if (buffAttribute != null)
Attribute = buffAttribute;
//初始化buff属性
if (buffAttribute.Buff != null)
{
//初始化buff属性
foreach (var keyValuePair in buffAttribute.Buff)
{
var buffInfo = BuffRegister.BuffInfos[keyValuePair.Key];
var buffInfo = PropFragmentRegister.BuffFragmentInfos[keyValuePair.Key];
var item = keyValuePair.Value;
switch (item.Length)
{
@ -62,11 +68,12 @@ public partial class BuffProp : PropActivity
break;
}
}
//显示纹理
if (!string.IsNullOrEmpty(ActivityBase.Icon))
{
SetDefaultTexture(ResourceManager.LoadTexture2D(ActivityBase.Icon));
}
}
//显示纹理
if (!string.IsNullOrEmpty(ActivityBase.Icon))
{
SetDefaultTexture(ResourceManager.LoadTexture2D(ActivityBase.Icon));
}
}
@ -215,6 +222,6 @@ public partial class BuffProp : PropActivity
return attr;
}
throw new Exception($"buff'{itemId}'没有在 BuffBase 表中配置属性数据!");
throw new Exception($"buff'{itemId}'没有在 BuffPropBase 表中配置属性数据!");
}
}

View File

@ -1,27 +0,0 @@

using Godot;
/// <summary>
/// 医药箱, 使用后恢复一颗红心
/// </summary>
[Tool]
public partial class ActiveProp5000 : ActiveProp
{
public override void OnInit()
{
base.OnInit();
AutoDestroy = true;
MaxCount = 10;
}
public override bool OnCheckUse()
{
return !Master.IsHpFull();
}
protected override int OnUse()
{
Master.Hp += 2;
return 1;
}
}

View File

@ -1,33 +0,0 @@

using Godot;
/// <summary>
/// 弹药箱, 使用后补全当前武器备用弹药
/// </summary>
[Tool]
public partial class ActiveProp5001 : ActiveProp
{
public override void OnInit()
{
base.OnInit();
AutoDestroy = true;
MaxCount = 10;
}
public override bool OnCheckUse()
{
return Master.WeaponPack.ActiveItem != null && !Master.WeaponPack.ActiveItem.IsAmmoFull();
}
protected override int OnUse()
{
var weapon = Master.WeaponPack.ActiveItem;
if (weapon != null)
{
weapon.SetTotalAmmo(weapon.Attribute.MaxAmmoCapacity);
return 1;
}
return 0;
}
}

View File

@ -45,6 +45,11 @@ public abstract partial class Weapon : ActivityObject, IPackageItem<Role>
/// 剩余弹药量(备用弹药)
/// </summary>
public int ResidueAmmo { get; private set; }
/// <summary>
/// 总弹药量(备用弹药 + 当前弹夹弹药)
/// </summary>
public int TotalAmmon => CurrAmmo + ResidueAmmo;
/// <summary>
/// 武器管的开火点

View File

@ -4,13 +4,8 @@ using System;
/// <summary>
/// 被动属性逻辑基类
/// </summary>
public abstract class BuffFragment : Component<BuffProp>
public abstract class BuffFragment : PropFragment
{
/// <summary>
/// 所属角色对象
/// </summary>
public Role Role => Master?.Master;
/// <summary>
/// 当道具被拾起时调用 (在 Master 赋值之后调用)
/// </summary>
@ -20,36 +15,4 @@ public abstract class BuffFragment : Component<BuffProp>
/// 当道具被移除时调用 (在 Master 置为 null 之前调用)
/// </summary>
public abstract void OnRemoveItem();
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1)
{
Debug.LogError($"'{GetType().FullName}'为实现1参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2)
{
Debug.LogError($"'{GetType().FullName}'为实现2参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2, float arg3)
{
Debug.LogError($"'{GetType().FullName}'为实现4参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2, float arg3, float arg4)
{
Debug.LogError($"'{GetType().FullName}'为实现4参数初始化函数!");
}
}

View File

@ -1,7 +1,7 @@
using System;
[AttributeUsage(AttributeTargets.Class)]
public class BuffAttribute : Attribute
public class BuffFragmentAttribute : Attribute
{
/// <summary>
/// Buff属性名称
@ -13,7 +13,7 @@ public class BuffAttribute : Attribute
/// </summary>
public string Description { get; set; }
public BuffAttribute(string buffName, string description)
public BuffFragmentAttribute(string buffName, string description)
{
BuffName = buffName;
Description = description;

View File

@ -0,0 +1,11 @@
/// <summary>
/// 主动道具使用条件基类
/// </summary>
public abstract class ConditionFragment : PropFragment
{
/// <summary>
/// 当检测是否可以使用时调用
/// </summary>
public abstract bool OnCheckUse();
}

View File

@ -0,0 +1,22 @@
using System;
[AttributeUsage(AttributeTargets.Class)]
public class ConditionFragmentAttribute : Attribute
{
/// <summary>
/// 条件名称
/// </summary>
public string ConditionName { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
public ConditionFragmentAttribute(string conditionName, string description)
{
ConditionName = conditionName;
Description = description;
}
}

View File

@ -0,0 +1,11 @@
/// <summary>
/// 主动道具使用效果基类
/// </summary>
public abstract class EffectFragment : PropFragment
{
/// <summary>
/// 使用道具的回调
/// </summary>
public abstract void OnUse();
}

View File

@ -0,0 +1,21 @@
using System;
[AttributeUsage(AttributeTargets.Class)]
public class EffectFragmentAttribute : Attribute
{
/// <summary>
/// 效果名称
/// </summary>
public string EffectName { get; set; }
/// <summary>
/// 描述
/// </summary>
public string Description { get; set; }
public EffectFragmentAttribute(string effectName, string description)
{
EffectName = effectName;
Description = description;
}
}

View File

@ -0,0 +1,43 @@
/// <summary>
/// 道具逻辑片段组件
/// </summary>
public abstract class PropFragment : Component<PropActivity>
{
/// <summary>
/// 所属角色对象
/// </summary>
public Role Role => Master?.Master;
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1)
{
Debug.LogError($"'{GetType().FullName}'为实现1参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2)
{
Debug.LogError($"'{GetType().FullName}'为实现2参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2, float arg3)
{
Debug.LogError($"'{GetType().FullName}'为实现4参数初始化函数!");
}
/// <summary>
/// 初始化被动属性参数
/// </summary>
public virtual void InitParam(float arg1, float arg2, float arg3, float arg4)
{
Debug.LogError($"'{GetType().FullName}'为实现4参数初始化函数!");
}
}

View File

@ -1,5 +1,5 @@
[Buff("ActivePropsCapacity", "主动道具背包容量 buff, 参数1为主动道具背包增加的容量")]
[BuffFragment("ActivePropsCapacity", "主动道具背包容量 buff, 参数1为主动道具背包增加的容量")]
public class Buff_ActivePropsCapacity : BuffFragment
{
private int _value;

View File

@ -1,5 +1,5 @@
[Buff("BulletBounceCount", "子弹弹射数量 buff, 参数1为增加的弹射次数")]
[BuffFragment("BulletBounceCount", "子弹弹射数量 buff, 参数1为增加的弹射次数")]
public class Buff_BulletBounceCount : BuffFragment
{
private int _value;

View File

@ -1,7 +1,7 @@
using Godot;
[Buff("BulletCount",
[BuffFragment("BulletCount",
"子弹数量 buff, " +
"参数1为子弹数量添加类型, 1: 具体数量, 2:百分比(小数), " +
"参数2为增加子弹的数量")]

View File

@ -1,11 +1,11 @@
using Godot;
[Buff("Damage",
"提升伤害buff, " +
[BuffFragment("BulletDamage",
"提升子弹伤害buff, " +
"参数1为伤害增加类型: 1:具体伤害, 2:百分比伤害(小数), " +
"参数2为增益伤害值")]
public class Buff_Damage : BuffFragment
public class Buff_BulletDamage : BuffFragment
{
private int _type;
private float _value;
@ -42,11 +42,19 @@ public class Buff_Damage : BuffFragment
private void CalcDamage1(int originDamage, RefValue<int> refValue)
{
if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
{
return;
}
refValue.Value += Mathf.CeilToInt(_value);
}
private void CalcDamage2(int originDamage, RefValue<int> refValue)
{
if (Role.WeaponPack.ActiveItem != null && Role.WeaponPack.ActiveItem.Attribute.IsMelee)
{
return;
}
if (_value > 0)
{
refValue.Value += Mathf.CeilToInt(originDamage * _value);

View File

@ -1,5 +1,5 @@
[Buff("BulletDeviationAngle",
[BuffFragment("BulletDeviationAngle",
"子弹偏移角度 buff, " +
"参数1为增加子弹偏移角度下限, " +
"参数2为增加子弹偏移角度上限, 单位角度制, 会从上限和下限随机抽取值")]

View File

@ -1,5 +1,5 @@
[Buff("BulletDistance",
[BuffFragment("BulletDistance",
"子弹射程 buff, " +
"参数1为射程增加类型: 1:具体射程, 2:百分比射程(小数), " +
"参数2为子弹增加的射程值")]

View File

@ -1,5 +1,5 @@
[Buff("BulletPenetration", "子弹穿透次数 buff, 参数1为增加的穿透次数")]
[BuffFragment("BulletPenetration", "子弹穿透次数 buff, 参数1为增加的穿透次数")]
public class Buff_BulletPenetration : BuffFragment
{
private int _value;

View File

@ -1,7 +1,7 @@
using Godot;
[Buff("BulletRepel",
[BuffFragment("BulletRepel",
"子弹击退 buff, " +
"参数1为击退增加类型: 1:具体击退值, 2:百分比击退值(小数), " +
"参数2为子弹增加的击退值")]

View File

@ -1,5 +1,5 @@
[Buff("BulletSpeed",
[BuffFragment("BulletSpeed",
"子弹速度 buff, " +
"参数1为射速增加类型: 1:具体射速, 2:百分比射速(小数), " +
"参数2为子弹增加的射速值")]

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
[Buff("MaxHp", "血量上限 buff, 参数1为血量上限值")]
[BuffFragment("MaxHp", "血量上限 buff, 参数1为血量上限值")]
public class Buff_MaxHp : BuffFragment
{
private List<ulong> _cacheId = new List<ulong>();

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
[Buff("MaxShield", "护盾上限buff, 参数1为护盾上限")]
[BuffFragment("MaxShield", "护盾上限buff, 参数1为护盾上限")]
public class Buff_MaxShield : BuffFragment
{
private List<ulong> _cacheId = new List<ulong>();

View File

@ -1,5 +1,5 @@
[Buff("MoveSpeed", "移速 buff, 参数1为移动速度值")]
[BuffFragment("MoveSpeed", "移速 buff, 参数1为移动速度值")]
public class Buff_MoveSpeed : BuffFragment
{
private float _moveSpeed;

View File

@ -1,5 +1,5 @@
[Buff("OffsetInjury", "受伤时有概率抵消伤害的buff, 参数1为抵消伤害概率百分比(小数)")]
[BuffFragment("OffsetInjury", "受伤时有概率抵消伤害的buff, 参数1为抵消伤害概率百分比(小数)")]
public class Buff_OffsetInjury : BuffFragment
{
private float _value;

View File

@ -1,5 +1,5 @@
[Buff("RandomBulletSpeed",
[BuffFragment("RandomBulletSpeed",
"子弹增加随机速度 buff, " +
"参数1为增加子弹速度下限, " +
"参数2为增加子弹速度上限, 会从上限和下限随机抽取值")]

View File

@ -1,7 +1,7 @@
using Godot;
[Buff("Scattering", "提高武器精准度buff, 参数1为提升的精准度百分比值(小数)")]
[BuffFragment("Scattering", "提高武器精准度buff, 参数1为提升的精准度百分比值(小数)")]
public class Buff_Scattering : BuffFragment
{
private float _value;

View File

@ -1,5 +1,5 @@
[Buff("ShieldRecoveryTime", "单格护盾减少的恢复时间, 参数1单位: 秒")]
[BuffFragment("ShieldRecoveryTime", "单格护盾减少的恢复时间, 参数1单位: 秒")]
public class Buff_ShieldRecoveryTime : BuffFragment
{
private float _time;

View File

@ -1,5 +1,5 @@
[Buff("WeaponCapacity", "武器背包容量 buff, 参数1为武器背包增加的容量")]
[BuffFragment("WeaponCapacity", "武器背包容量 buff, 参数1为武器背包增加的容量")]
public class Buff_WeaponCapacity : BuffFragment
{
private int _value;

View File

@ -1,5 +1,5 @@
[Buff("WoundedInvincibleTime", "延长无敌时间buff, 参数1为延长时间, 单位秒")]
[BuffFragment("WoundedInvincibleTime", "延长无敌时间buff, 参数1为延长时间, 单位秒")]
public class Buff_WoundedInvincibleTime : BuffFragment
{
private float _time;

View File

@ -0,0 +1,29 @@
[ConditionFragment("AmmoFull",
"判断当前武器弹药状态, " +
"参数1可选值: 0:判断非满弹药, 1:判断满弹药")]
public class Cond_AmmoFull : ConditionFragment
{
private int _type;
public override void InitParam(float arg1)
{
_type = (int)arg1;
}
public override bool OnCheckUse()
{
if (Role.WeaponPack.ActiveItem == null)
{
return false;
}
if (_type == 0)
{
return !Role.WeaponPack.ActiveItem.IsAmmoFull();
}
else
{
return Role.WeaponPack.ActiveItem.IsAmmoFull();
}
}
}

View File

@ -0,0 +1,25 @@
[ConditionFragment("HpFull",
"判断满血状态, " +
"参数1可选值: 0:判断非满血, 1:判断满血")]
public class Cond_HpFull : ConditionFragment
{
private int _type;
public override void InitParam(float arg1)
{
_type = (int)arg1;
}
public override bool OnCheckUse()
{
if (_type == 0)
{
return !Role.IsHpFull();
}
else
{
return Role.IsHpFull();
}
}
}

View File

@ -0,0 +1,16 @@
[EffectFragment("Hp", "修改血量, 参数1为血量变化的具体值")]
public class Eff_Hp : EffectFragment
{
private int _value;
public override void InitParam(float arg1)
{
_value = (int) arg1;
}
public override void OnUse()
{
Role.Hp += _value;
}
}

View File

@ -0,0 +1,28 @@
[EffectFragment("TotalAmmo",
"修改武器总弹药量, " +
"参数1(选填)为弹药变化的具体值, 如果不传则表示补满弹药")]
public class Eff_TotalAmmo : EffectFragment
{
private bool _initParam = false;
private int _value;
public override void InitParam(float arg1)
{
_initParam = true;
_value = (int) arg1;
}
public override void OnUse()
{
var weapon = Role.WeaponPack.ActiveItem;
if (_initParam)
{
weapon.SetTotalAmmo(weapon.TotalAmmon + _value);
}
else
{
weapon.SetTotalAmmo(weapon.Attribute.MaxAmmoCapacity);
}
}
}

View File

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
/// <summary>
/// buff 属性数据
/// </summary>
public class BuffInfo
{
/// <summary>
/// buff 名称
/// </summary>
public string Name;
/// <summary>
/// buff 描述
/// </summary>
public string Description;
/// <summary>
/// buff 可传参数
/// </summary>
public List<int> Params;
/// <summary>
/// buff 类
/// </summary>
public Type Type;
public BuffInfo(string name, string description, Type type)
{
Name = name;
Description = description;
Type = type;
Params = new List<int>();
}
public BuffInfo(string name, string description, List<int> paramsList, Type type)
{
Name = name;
Description = description;
Params = paramsList;
Type = type;
}
}

View File

@ -0,0 +1,30 @@
using System;
/// <summary>
/// 道具逻辑片段数据
/// </summary>
public class PropFragmentInfo
{
/// <summary>
/// buff 名称
/// </summary>
public string Name;
/// <summary>
/// buff 描述
/// </summary>
public string Description;
/// <summary>
/// buff 类
/// </summary>
public Type Type;
public PropFragmentInfo(string name, string description, Type type)
{
Name = name;
Description = description;
Type = type;
}
}

View File

@ -1,37 +0,0 @@
using System.Collections.Generic;
/// <summary>
/// buff 注册类, 调用 Init() 函数初始化数据
/// 注意: 该类为 Tools 面板下自动生成的, 请不要手动编辑!
/// </summary>
public class BuffRegister
{
/// <summary>
/// 所有 buff 信息
/// </summary>
public static Dictionary<string, BuffInfo> BuffInfos { get; private set; }
/// <summary>
/// 初始化 buff
/// </summary>
public static void Init()
{
BuffInfos = new Dictionary<string, BuffInfo>();
BuffInfos.Add("ActivePropsCapacity", new BuffInfo("ActivePropsCapacity", null, new List<int>() { 1 }, typeof(Buff_ActivePropsCapacity)));
BuffInfos.Add("BulletBounceCount", new BuffInfo("BulletBounceCount", null, new List<int>() { 1 }, typeof(Buff_BulletBounceCount)));
BuffInfos.Add("BulletCount", new BuffInfo("BulletCount", null, new List<int>() { 2 }, typeof(Buff_BulletCount)));
BuffInfos.Add("BulletDeviationAngle", new BuffInfo("BulletDeviationAngle", null, new List<int>() { 2 }, typeof(Buff_BulletDeviationAngle)));
BuffInfos.Add("BulletDistance", new BuffInfo("BulletDistance", null, new List<int>() { 2 }, typeof(Buff_BulletDistance)));
BuffInfos.Add("BulletPenetration", new BuffInfo("BulletPenetration", null, new List<int>() { 1 }, typeof(Buff_BulletPenetration)));
BuffInfos.Add("BulletRepel", new BuffInfo("BulletRepel", null, new List<int>() { 2 }, typeof(Buff_BulletRepel)));
BuffInfos.Add("BulletSpeed", new BuffInfo("BulletSpeed", null, new List<int>() { 2 }, typeof(Buff_BulletSpeed)));
BuffInfos.Add("Damage", new BuffInfo("Damage", null, new List<int>() { 2 }, typeof(Buff_Damage)));
BuffInfos.Add("MaxHp", new BuffInfo("MaxHp", null, new List<int>() { 1 }, typeof(Buff_MaxHp)));
BuffInfos.Add("MaxShield", new BuffInfo("MaxShield", null, new List<int>() { 1 }, typeof(Buff_MaxShield)));
BuffInfos.Add("MoveSpeed", new BuffInfo("MoveSpeed", null, new List<int>() { 1 }, typeof(Buff_MoveSpeed)));
BuffInfos.Add("OffsetInjury", new BuffInfo("OffsetInjury", null, new List<int>() { 1 }, typeof(Buff_OffsetInjury)));
BuffInfos.Add("RandomBulletSpeed", new BuffInfo("RandomBulletSpeed", null, new List<int>() { 2 }, typeof(Buff_RandomBulletSpeed)));
BuffInfos.Add("Scattering", new BuffInfo("Scattering", null, new List<int>() { 1 }, typeof(Buff_Scattering)));
BuffInfos.Add("ShieldRecoveryTime", new BuffInfo("ShieldRecoveryTime", null, new List<int>() { 1 }, typeof(Buff_ShieldRecoveryTime)));
BuffInfos.Add("WeaponCapacity", new BuffInfo("WeaponCapacity", null, new List<int>() { 1 }, typeof(Buff_WeaponCapacity)));
BuffInfos.Add("WoundedInvincibleTime", new BuffInfo("WoundedInvincibleTime", null, new List<int>() { 1 }, typeof(Buff_WoundedInvincibleTime)));
}
}

View File

@ -0,0 +1,91 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Godot;
/// <summary>
/// buff 属性注册类, 调用 Init() 函数初始化数据
/// </summary>
public class PropFragmentRegister
{
/// <summary>
/// 所有 buff 属性信息
/// </summary>
public static Dictionary<string, PropFragmentInfo> BuffFragmentInfos { get; private set; }
/// <summary>
/// 所有主动道具条件数据
/// </summary>
public static Dictionary<string, PropFragmentInfo> ConditionFragmentInfos { get; private set; }
/// <summary>
/// 所有主动道具效果数据
/// </summary>
public static Dictionary<string, PropFragmentInfo> EffectFragmentInfos { get; private set; }
/// <summary>
/// 初始化 buff
/// </summary>
public static void Init()
{
BuffFragmentInfos = new Dictionary<string, PropFragmentInfo>();
ConditionFragmentInfos = new Dictionary<string, PropFragmentInfo>();
EffectFragmentInfos = new Dictionary<string, PropFragmentInfo>();
var types = typeof(PropFragmentRegister).Assembly.GetTypes();
//包含[BuffAttribute]特性
var buffs = types.Where(type =>
type.IsClass && !type.IsAbstract && type.IsAssignableTo(typeof(BuffFragment)));
foreach (var type in buffs)
{
var attribute = (BuffFragmentAttribute)type.GetCustomAttribute(typeof(BuffFragmentAttribute), false);
if (attribute != null)
{
if (BuffFragmentInfos.ContainsKey(attribute.BuffName))
{
GD.PrintErr($"Buff '{attribute.BuffName}' 重名!");
continue;
}
var buffInfo = new PropFragmentInfo(attribute.BuffName, attribute.Description, type);
BuffFragmentInfos.Add(attribute.BuffName, buffInfo);
}
}
//包含[ConditionAttribute]特性
var conditions = types.Where(type =>
type.IsClass && !type.IsAbstract && type.IsAssignableTo(typeof(ConditionFragment)));
foreach (var type in conditions)
{
var attribute = (ConditionFragmentAttribute)type.GetCustomAttribute(typeof(ConditionFragmentAttribute), false);
if (attribute != null)
{
if (ConditionFragmentInfos.ContainsKey(attribute.ConditionName))
{
GD.PrintErr($"Condition '{attribute.ConditionName}' 重名!");
continue;
}
var conditionInfo = new PropFragmentInfo(attribute.ConditionName, attribute.Description, type);
ConditionFragmentInfos.Add(attribute.ConditionName, conditionInfo);
}
}
//包含[EffectAttribute]特性
var effects = types.Where(type =>
type.IsClass && !type.IsAbstract && type.IsAssignableTo(typeof(EffectFragment)));
foreach (var type in effects)
{
var attribute = (EffectFragmentAttribute)type.GetCustomAttribute(typeof(EffectFragmentAttribute), false);
if (attribute != null)
{
if (EffectFragmentInfos.ContainsKey(attribute.EffectName))
{
GD.PrintErr($"Effect '{attribute.EffectName}' 重名!");
continue;
}
var effectInfo = new PropFragmentInfo(attribute.EffectName, attribute.Description, type);
EffectFragmentInfos.Add(attribute.EffectName, effectInfo);
}
}
}
}