重构主动道具中

This commit is contained in:
小李xl 2024-03-16 00:47:17 +08:00
parent ec64cb6d7c
commit b736a60bd1
28 changed files with 57 additions and 56 deletions

Binary file not shown.

View File

@ -1,11 +1,11 @@
[gd_scene load_steps=7 format=3 uid="uid://dfpic4nubu7cf"]
[ext_resource type="Script" path="res://src/game/activity/prop/BuffActivity.cs" id="1_3ya6n"]
[ext_resource type="Shader" path="res://resource/material/Blend.gdshader" id="2_p5e2l"]
[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"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mrkt4"]
resource_local_to_scene = true
shader = ExtResource("2_p5e2l")
shader = ExtResource("2_imicp")
shader_parameter/blend = Color(0, 0, 0, 0.470588)
shader_parameter/schedule = 1.0
shader_parameter/modulate = Color(1, 1, 1, 1)
@ -17,7 +17,7 @@ shader_parameter/grey = 0.0
[sub_resource type="ShaderMaterial" id="ShaderMaterial_b6ii6"]
resource_local_to_scene = true
shader = ExtResource("2_p5e2l")
shader = ExtResource("2_imicp")
shader_parameter/blend = Color(1, 1, 1, 1)
shader_parameter/schedule = 0.0
shader_parameter/modulate = Color(1, 1, 1, 1)
@ -33,9 +33,9 @@ resource_local_to_scene = true
[sub_resource type="RectangleShape2D" id="RectangleShape2D_cpqup"]
size = Vector2(12, 10)
[node name="BuffActivity" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
[node name="BuffProp" type="CharacterBody2D" node_paths=PackedStringArray("ShadowSprite", "AnimatedSprite", "Collision")]
collision_layer = 4
script = ExtResource("1_3ya6n")
script = ExtResource("1_nlcp6")
ShadowSprite = NodePath("ShadowSprite")
AnimatedSprite = NodePath("AnimatedSprite")
Collision = NodePath("Collision")

View File

@ -101,7 +101,7 @@ public partial class GameApplication : Node2D, ICoroutine
//初始化敌人数据
Enemy.InitEnemyAttribute();
//初始化buff数据
BuffActivity.InitBuffAttribute();
BuffProp.InitBuffAttribute();
DungeonConfig = new DungeonConfig();
DungeonConfig.GroupName = "Test1";

View File

@ -1,18 +1,15 @@
using System.Collections.Generic;
using Godot;
/// <summary>
/// 主动使用道具
/// </summary>
public abstract partial class ActivePropActivity : PropActivity, IPackageItem<Role>
[Tool]
public partial class ActiveProp : PropActivity, IPackageItem<Role>
{
public int PackageIndex { get; set; }
/// <summary>
/// 道具是否可以叠加
/// </summary>
public bool Superposition { get; set; } = false;
/// <summary>
/// 道具可使用次数
/// </summary>
@ -92,16 +89,22 @@ public abstract partial class ActivePropActivity : PropActivity, IPackageItem<Ro
//冷却计时器
private float _cooldownTimer = 0;
/// <summary>
/// 当检测是否可以使用时调用
/// </summary>
public abstract bool OnCheckUse();
public virtual bool OnCheckUse()
{
return true;
}
/// <summary>
/// 当道具被使用时调用, 函数返回值为消耗数量
/// </summary>
protected abstract int OnUse();
protected virtual int OnUse()
{
return 1;
}
/// <summary>
/// 道具数量改变时调用
@ -251,7 +254,7 @@ public abstract partial class ActivePropActivity : PropActivity, IPackageItem<Ro
else
{
//处理同类型道具
if (Superposition && item.Count < item.MaxCount) //允许叠加
if (item.Count < item.MaxCount) //允许叠加
{
if (item.Count + Count > item.MaxCount)
{
@ -292,7 +295,7 @@ public abstract partial class ActivePropActivity : PropActivity, IPackageItem<Ro
}
//处理同类型道具
if (Superposition && item.Count < item.MaxCount) //允许叠加
if (item.Count < item.MaxCount) //允许叠加
{
return new CheckInteractiveResult(this, true, CheckInteractiveResult.InteractiveType.Bullet);
}

View File

@ -8,7 +8,7 @@ using Godot;
/// 通用被动道具实体类
/// </summary>
[Tool]
public partial class BuffActivity : PropActivity
public partial class BuffProp : PropActivity
{
//被动属性
private readonly List<BuffFragment> _buffFragment = new List<BuffFragment>();

View File

@ -5,14 +5,13 @@ using Godot;
/// 医药箱, 使用后恢复一颗红心
/// </summary>
[Tool]
public partial class ActiveProp5000 : ActivePropActivity
public partial class ActiveProp5000 : ActiveProp
{
public override void OnInit()
{
base.OnInit();
AutoDestroy = true;
MaxCount = 10;
Superposition = true;
}
public override bool OnCheckUse()

View File

@ -5,12 +5,11 @@ using Godot;
/// 弹药箱, 使用后补全当前武器备用弹药
/// </summary>
[Tool]
public partial class ActiveProp5001 : ActivePropActivity
public partial class ActiveProp5001 : ActiveProp
{
public override void OnInit()
{
base.OnInit();
Superposition = true;
AutoDestroy = true;
MaxCount = 10;
}

View File

@ -54,12 +54,12 @@ public abstract partial class Role : ActivityObject
/// <summary>
/// 携带的被动道具列表
/// </summary>
public List<BuffActivity> BuffPropPack { get; } = new List<BuffActivity>();
public List<BuffProp> BuffPropPack { get; } = new List<BuffProp>();
/// <summary>
/// 携带的主动道具包裹
/// </summary>
public Package<ActivePropActivity, Role> ActivePropsPack { get; private set; }
public Package<ActiveProp, Role> ActivePropsPack { get; private set; }
/// <summary>
/// 互动碰撞区域
@ -431,42 +431,42 @@ public abstract partial class Role : ActivityObject
/// <summary>
/// 当拾起某个主动道具时调用
/// </summary>
protected virtual void OnPickUpActiveProp(ActivePropActivity activePropActivity)
protected virtual void OnPickUpActiveProp(ActiveProp activeProp)
{
}
/// <summary>
/// 当移除某个主动道具时调用
/// </summary>
protected virtual void OnRemoveActiveProp(ActivePropActivity activePropActivity)
protected virtual void OnRemoveActiveProp(ActiveProp activeProp)
{
}
/// <summary>
/// 当切换到某个主动道具时调用
/// </summary>
protected virtual void OnExchangeActiveProp(ActivePropActivity activePropActivity)
protected virtual void OnExchangeActiveProp(ActiveProp activeProp)
{
}
/// <summary>
/// 当拾起某个被动道具时调用
/// </summary>
protected virtual void OnPickUpBuffProp(BuffActivity buffActivity)
protected virtual void OnPickUpBuffProp(BuffProp buffProp)
{
}
/// <summary>
/// 当移除某个被动道具时调用
/// </summary>
protected virtual void OnRemoveBuffProp(BuffActivity buffActivity)
protected virtual void OnRemoveBuffProp(BuffProp buffProp)
{
}
public override void OnInit()
{
RoleState = OnCreateRoleState();
ActivePropsPack = AddComponent<Package<ActivePropActivity, Role>>();
ActivePropsPack = AddComponent<Package<ActiveProp, Role>>();
ActivePropsPack.SetCapacity(RoleState.CanPickUpWeapon ? 1 : 0);
_startScale = Scale;
@ -617,7 +617,7 @@ public abstract partial class Role : ActivityObject
var props = ActivePropsPack.ItemSlot;
if (props.Length > 0)
{
props = (ActivePropActivity[])props.Clone();
props = (ActiveProp[])props.Clone();
foreach (var prop in props)
{
if (prop != null && !prop.IsDestroyed)
@ -673,15 +673,15 @@ public abstract partial class Role : ActivityObject
/// <summary>
/// 拾起主动道具, 返回是否成功拾起, 如果不想立刻切换到该道具, exchange 请传 false
/// </summary>
/// <param name="activePropActivity">主动道具对象</param>
/// <param name="activeProp">主动道具对象</param>
/// <param name="exchange">是否立即切换到该道具, 默认 true </param>
public bool PickUpActiveProp(ActivePropActivity activePropActivity, bool exchange = true)
public bool PickUpActiveProp(ActiveProp activeProp, bool exchange = true)
{
if (ActivePropsPack.PickupItem(activePropActivity, exchange) != -1)
if (ActivePropsPack.PickupItem(activeProp, exchange) != -1)
{
//从可互动队列中移除
InteractiveItemList.Remove(activePropActivity);
OnPickUpActiveProp(activePropActivity);
InteractiveItemList.Remove(activeProp);
OnPickUpActiveProp(activeProp);
return true;
}
@ -716,28 +716,28 @@ public abstract partial class Role : ActivityObject
/// <summary>
/// 拾起被动道具, 返回是否成功拾起
/// </summary>
/// <param name="buffActivity">被动道具对象</param>
public bool PickUpBuffProp(BuffActivity buffActivity)
/// <param name="buffProp">被动道具对象</param>
public bool PickUpBuffProp(BuffProp buffProp)
{
if (BuffPropPack.Contains(buffActivity))
if (BuffPropPack.Contains(buffProp))
{
Debug.LogError("被动道具已经在背包中了!");
return false;
}
BuffPropPack.Add(buffActivity);
buffActivity.Master = this;
OnPickUpBuffProp(buffActivity);
buffActivity.OnPickUpItem();
BuffPropPack.Add(buffProp);
buffProp.Master = this;
OnPickUpBuffProp(buffProp);
buffProp.OnPickUpItem();
return true;
}
/// <summary>
/// 扔掉指定的被动道具
/// </summary>
/// <param name="buffActivity"></param>
public void ThrowBuffProp(BuffActivity buffActivity)
/// <param name="buffProp"></param>
public void ThrowBuffProp(BuffProp buffProp)
{
var index = BuffPropPack.IndexOf(buffActivity);
var index = BuffPropPack.IndexOf(buffProp);
if (index < 0)
{
Debug.LogError("当前道具不在角色背包中!");

View File

@ -354,24 +354,24 @@ public partial class Player : Role
UiManager.Open_Settlement();
}
protected override void OnPickUpActiveProp(ActivePropActivity activePropActivity)
protected override void OnPickUpActiveProp(ActiveProp activeProp)
{
EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, activePropActivity);
EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, activeProp);
}
protected override void OnRemoveActiveProp(ActivePropActivity activePropActivity)
protected override void OnRemoveActiveProp(ActiveProp activeProp)
{
EventManager.EmitEvent(EventEnum.OnPlayerRemoveProp, activePropActivity);
EventManager.EmitEvent(EventEnum.OnPlayerRemoveProp, activeProp);
}
protected override void OnPickUpBuffProp(BuffActivity buffActivity)
protected override void OnPickUpBuffProp(BuffProp buffProp)
{
EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, buffActivity);
EventManager.EmitEvent(EventEnum.OnPlayerPickUpProp, buffProp);
}
protected override void OnRemoveBuffProp(BuffActivity buffActivity)
protected override void OnRemoveBuffProp(BuffProp buffProp)
{
EventManager.EmitEvent(EventEnum.OnPlayerRemoveProp, buffActivity);
EventManager.EmitEvent(EventEnum.OnPlayerRemoveProp, buffProp);
}
/// <summary>

View File

@ -4,7 +4,7 @@ using System;
/// <summary>
/// 被动属性逻辑基类
/// </summary>
public abstract partial class BuffFragment : Component<BuffActivity>
public abstract class BuffFragment : Component<BuffProp>
{
/// <summary>
/// 所属角色对象