调整Prop

This commit is contained in:
小李xl 2024-03-18 19:20:06 +08:00
parent 9e07cd71db
commit 82b0732c39
9 changed files with 252 additions and 98 deletions

View File

@ -1043,42 +1043,11 @@ public partial class ActivityObject : CharacterBody2D, IDestroy, ICoroutine
}
#endif
var newDelta = (float)delta;
if (EnableCustomBehavior)
{
Process(newDelta);
}
UpdateProcess(newDelta);
//更新组件
if (_components.Count > 0)
{
_updatingComp = true;
if (EnableCustomBehavior) //启用所有组件
{
for (int i = 0; i < _components.Count; i++)
{
if (IsDestroyed) return;
var temp = _components[i].Value;
if (temp != null && temp.Enable)
{
temp.Process(newDelta);
}
}
}
else //只更新 MoveController 组件
{
if (MoveController.Enable)
{
MoveController.Process(newDelta);
}
}
_updatingComp = false;
if (_changeComponents.Count > 0)
{
RefreshComponent();
}
}
UpdateComponentProcess(newDelta);
// 更新下坠处理逻辑
UpdateFall(newDelta);
@ -1109,7 +1078,7 @@ public partial class ActivityObject : CharacterBody2D, IDestroy, ICoroutine
}
//协程更新
ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, newDelta);
UpdateCoroutine(newDelta);
//调试绘制
if (IsDebug)
@ -1118,6 +1087,110 @@ public partial class ActivityObject : CharacterBody2D, IDestroy, ICoroutine
}
}
/// <summary>
/// 触发调用 Process() 函数
/// </summary>
public void UpdateProcess(float delta)
{
if (EnableCustomBehavior)
{
Process(delta);
}
}
/// <summary>
/// 触发调用 PhysicsProcess() 函数
/// </summary>
public void UpdatePhysicsProcess(float delta)
{
if (EnableCustomBehavior)
{
PhysicsProcess(delta);
}
}
/// <summary>
/// 更新组件
/// </summary>
public void UpdateComponentProcess(float delta)
{
//更新组件
if (_components.Count > 0)
{
_updatingComp = true;
if (EnableCustomBehavior) //启用所有组件
{
for (int i = 0; i < _components.Count; i++)
{
if (IsDestroyed) return;
var temp = _components[i].Value;
if (temp != null && temp.Enable)
{
temp.Process(delta);
}
}
}
else //只更新 MoveController 组件
{
if (MoveController.Enable)
{
MoveController.Process(delta);
}
}
_updatingComp = false;
if (_changeComponents.Count > 0)
{
RefreshComponent();
}
}
}
/// <summary>
/// 物理帧更新组件
/// </summary>
public void UpdateComponentPhysicsProcess(float delta)
{
if (_components.Count > 0)
{
_updatingComp = true;
if (EnableCustomBehavior) //启用所有组件
{
for (int i = 0; i < _components.Count; i++)
{
if (IsDestroyed) return;
var temp = _components[i].Value;
if (temp != null && temp.Enable)
{
temp.PhysicsProcess(delta);
}
}
}
else //只更新 MoveController 组件
{
if (MoveController.Enable)
{
MoveController.PhysicsProcess(delta);
}
}
_updatingComp = false;
if (_changeComponents.Count > 0)
{
RefreshComponent();
}
}
}
/// <summary>
/// 更新协程
/// </summary>
public void UpdateCoroutine(float delta)
{
ProxyCoroutineHandler.ProxyUpdateCoroutine(ref _coroutineList, delta);
}
/// <summary>
/// 更新下坠处理逻辑
/// </summary>
@ -1275,41 +1348,10 @@ public partial class ActivityObject : CharacterBody2D, IDestroy, ICoroutine
}
#endif
var newDelta = (float)delta;
if (EnableCustomBehavior)
{
PhysicsProcess(newDelta);
}
UpdatePhysicsProcess(newDelta);
//更新组件
if (_components.Count > 0)
{
_updatingComp = true;
if (EnableCustomBehavior) //启用所有组件
{
for (int i = 0; i < _components.Count; i++)
{
if (IsDestroyed) return;
var temp = _components[i].Value;
if (temp != null && temp.Enable)
{
temp.PhysicsProcess(newDelta);
}
}
}
else //只更新 MoveController 组件
{
if (MoveController.Enable)
{
MoveController.PhysicsProcess(newDelta);
}
}
_updatingComp = false;
if (_changeComponents.Count > 0)
{
RefreshComponent();
}
}
UpdateComponentPhysicsProcess(newDelta);
}
//更新新增/移除的组件

View File

@ -259,6 +259,11 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
{
if (!fragment.OnCheckUse()) return false;
}
foreach (var fragment in _effectFragment)
{
if (!fragment.OnCheckUse()) return false;
}
return true;
}
@ -303,16 +308,6 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
}
protected override void Process(float delta)
{
RunUpdate(delta);
}
public override void PackProcess(float delta)
{
RunUpdate(delta);
}
private void RunUpdate(float delta)
{
if (CheckAutoDestroy())
{
@ -337,7 +332,7 @@ public partial class ActiveProp : PropActivity, IPackageItem<Role>
ChargeProgress += AutoChargeSpeed * delta;
}
}
//检测是否达到自动销毁的条件
private bool CheckAutoDestroy()
{

View File

@ -26,13 +26,6 @@ public abstract partial class PropActivity : ActivityObject
ThrowCollisionMask = PhysicsLayer.Wall;
}
/// <summary>
/// 如果道具放入了角色背包中, 则每帧调用
/// </summary>
public virtual void PackProcess(float delta)
{
}
/// <summary>
/// 触发扔掉道具效果, 并不会管道具是否在道具背包中
/// </summary>

View File

@ -611,12 +611,15 @@ public abstract partial class Role : ActivityObject
//被动道具更新
if (BuffPropPack.Count > 0)
{
var buffProps = BuffPropPack.ToArray();
foreach (var prop in buffProps)
var buffProps = BuffPropPack;
for (var i = 0; i < buffProps.Count; i++)
{
if (!prop.IsDestroyed)
var prop = buffProps[i];
if (!prop.IsDestroyed && prop.Master != null)
{
prop.PackProcess(delta);
prop.UpdateProcess(delta);
prop.UpdateComponentProcess(delta);
prop.UpdateCoroutine(delta);
}
}
}
@ -625,12 +628,14 @@ public abstract partial class Role : ActivityObject
var props = ActivePropsPack.ItemSlot;
if (props.Length > 0)
{
props = (ActiveProp[])props.Clone();
foreach (var prop in props)
for (var i = 0; i < props.Length; i++)
{
if (prop != null && !prop.IsDestroyed)
var prop = props[i];
if (prop != null && !prop.IsDestroyed && prop.Master != null)
{
prop.PackProcess(delta);
prop.UpdateProcess(delta);
prop.UpdateComponentProcess(delta);
prop.UpdateCoroutine(delta);
}
}
}
@ -644,7 +649,40 @@ public abstract partial class Role : ActivityObject
TipRoot.Scale = new Vector2(-1, 1);
}
}
protected override void PhysicsProcess(float delta)
{
//被动道具更新
if (BuffPropPack.Count > 0)
{
var buffProps = BuffPropPack;
for (var i = 0; i < buffProps.Count; i++)
{
var prop = buffProps[i];
if (!prop.IsDestroyed && prop.Master != null)
{
prop.UpdatePhysicsProcess(delta);
prop.UpdateComponentPhysicsProcess(delta);
}
}
}
//主动道具调用更新
var props = ActivePropsPack.ItemSlot;
if (props.Length > 0)
{
for (var i = 0; i < props.Length; i++)
{
var prop = props[i];
if (prop != null && !prop.IsDestroyed && prop.Master != null)
{
prop.UpdatePhysicsProcess(delta);
prop.UpdateComponentPhysicsProcess(delta);
}
}
}
}
/// <summary>
/// 初始化瞄准辅助线
/// </summary>
@ -687,6 +725,7 @@ public abstract partial class Role : ActivityObject
{
if (ActivePropsPack.PickupItem(activeProp, exchange) != -1)
{
activeProp.MoveController.Enable = false;
//从可互动队列中移除
InteractiveItemList.Remove(activeProp);
OnPickUpActiveProp(activeProp);
@ -715,6 +754,7 @@ public abstract partial class Role : ActivityObject
return;
}
activeProp.MoveController.Enable = true;
ActivePropsPack.RemoveItem(index);
OnRemoveActiveProp(activeProp);
//播放抛出效果

View File

@ -4,6 +4,11 @@
/// </summary>
public abstract class ConditionFragment : PropFragment
{
/// <summary>
/// 当前组件所挂载的游戏对象
/// </summary>
public new ActiveProp Master => (ActiveProp)base.Master;
/// <summary>
/// 当检测是否可以使用时调用
/// </summary>

View File

@ -4,6 +4,19 @@
/// </summary>
public abstract class EffectFragment : PropFragment
{
/// <summary>
/// 当前组件所挂载的游戏对象
/// </summary>
public new ActiveProp Master => (ActiveProp)base.Master;
/// <summary>
/// 当检测是否可以使用时调用
/// </summary>
public virtual bool OnCheckUse()
{
return true;
}
/// <summary>
/// 使用道具的回调
/// </summary>
@ -16,4 +29,12 @@ public abstract class EffectFragment : PropFragment
public override void OnRemoveItem()
{
}
/// <summary>
/// 返回是否正在使用当前道具
/// </summary>
public bool IsActive()
{
return Role != null && Role.ActivePropsPack.ActiveItem == Master;
}
}

View File

@ -10,14 +10,22 @@ public abstract class PropFragment : Component<PropActivity>
public Role Role => Master?.Master;
/// <summary>
/// 当道具被拾起时调用 (在 Master 赋值之后调用)
/// 当道具被拾起时调用 (在 Role 赋值之后调用)
/// </summary>
public abstract void OnPickUpItem();
/// <summary>
/// 当道具被移除时调用 (在 Master 置为 null 之前调用)
/// 当道具被移除时调用 (在 Role 置为 null 之前调用)
/// </summary>
public abstract void OnRemoveItem();
/// <summary>
/// 返回道具是否在背包中
/// </summary>
public bool IsInPackage()
{
return Master != null;
}
/// <summary>
/// 初始化被动属性参数

View File

@ -0,0 +1,44 @@
using Godot;
[EffectFragment("AreaTrigger", "")]
public class Eff_AreaTrigger : EffectFragment
{
private Area2D _areaNode;
private CollisionShape2D _shapeNode;
private CircleShape2D _shape;
public override void Ready()
{
_areaNode = new Area2D();
_shapeNode = new CollisionShape2D();
_shape = new CircleShape2D();
_shapeNode.Shape = _shape;
_areaNode.AddChild(_shapeNode);
AddChild(_areaNode);
}
public override void OnDestroy()
{
_areaNode.QueueFree();
_shapeNode.QueueFree();
}
public override void OnUse()
{
}
public override void OnPickUpItem()
{
RemoveChild(_areaNode);
Role.AddChild(_areaNode);
}
public override void OnRemoveItem()
{
Role.RemoveChild(_areaNode);
AddChild(_areaNode);
}
}

View File

@ -13,9 +13,13 @@ public class Eff_PiggyBank : EffectFragment
_value = arg1;
}
public override bool OnCheckUse()
{
return _currValue > 0;
}
public override void OnUse()
{
Debug.Log("存入了: " + _currValue);
var goldList = Utils.GetGoldList(Mathf.FloorToInt(_currValue * _value));
foreach (var id in goldList)
{
@ -27,6 +31,8 @@ public class Eff_PiggyBank : EffectFragment
0
);
}
_currValue = 0;
}
public override void OnPickUpItem()