增加收获属性逻辑,优化掉落物表现效果

This commit is contained in:
2026-10-05 17:02:29 +08:00
parent d55b1013ca
commit 7590d78e74
53 changed files with 1633 additions and 241 deletions
@@ -0,0 +1,107 @@
using Cysharp.Threading.Tasks;
using GameFramework.Event;
using SepCore.AsyncTask;
using SepCore.CustomComponent;
using SepCore.Definition;
using SepCore.Entity;
using SepCore.Event;
using Random = UnityEngine.Random;
namespace SepCore.Battle
{
public sealed class DropService
{
private const float VacuumMaxDuration = 0.8f;
private const float VacuumAbsorbSpeed = 30f;
private TbGlobalConfig _globalConfig;
private bool _isListening;
private float _vacuumTimer;
public void Subscribe()
{
if (_isListening)
{
return;
}
_globalConfig = GameEntry.Luban.Global;
GameEntry.Event.Subscribe(DropSpawnRequestedEventArgs.EventId, OnDropSpawnRequested);
_isListening = true;
}
public void Unsubscribe()
{
if (!_isListening)
{
return;
}
_globalConfig = null;
GameEntry.Event.Unsubscribe(DropSpawnRequestedEventArgs.EventId, OnDropSpawnRequested);
_isListening = false;
}
public void StartVacuum()
{
_vacuumTimer = VacuumMaxDuration;
GameEntry.SimulationWorld.TriggerFullMapMagnet();
GameEntry.SimulationWorld.SyncPlayerAbsorbSettings(999f, VacuumAbsorbSpeed,
_globalConfig.CollectDistance, _globalConfig.RecoilDistance,
_globalConfig.RecoilDuration, _globalConfig.DashAccelerationDuration,
_globalConfig.DashMaxSpeedMultiplier, _globalConfig.TurnSpeed);
}
public bool UpdateVacuum(float elapseSeconds, Player player)
{
_vacuumTimer -= elapseSeconds;
if (GameEntry.SimulationWorld.PickupCount > 0 && _vacuumTimer > 0f)
{
return false;
}
CollectAllRemainingDrops(player);
return true;
}
public void HideAllDrops()
{
_vacuumTimer = 0f;
var entityGroup = GameEntry.Entity.GetEntityGroup(_globalConfig.DropGroupName);
var entities = entityGroup.GetAllEntities();
foreach (var entity in entities)
{
GameEntry.Entity.HideEntity(entity.Id);
}
}
private void CollectAllRemainingDrops(Player player)
{
var entityGroup = GameEntry.Entity.GetEntityGroup(_globalConfig.DropGroupName);
var entities = entityGroup.GetAllEntities();
foreach (var entity in entities)
{
if (entity is UnityGameFramework.Runtime.Entity runtimeEntity && runtimeEntity.Logic is DropEntity drop)
{
drop.TryCollect(player);
}
}
}
private void OnDropSpawnRequested(object sender, GameEventArgs e)
{
var eventArgs = (DropSpawnRequestedEventArgs)e;
int idx = Random.Range(0, _globalConfig.DropEntityAssetNames.Count);
var dropEntityAssetName = _globalConfig.DropEntityAssetNames[idx];
var data = new DropData(_globalConfig.DropEntityCoinCount, _globalConfig.DropEntityExpCount,
GameEntry.Entity.NextId(), dropEntityAssetName)
{
Position = eventArgs.Position
};
GameEntry.Entity.ShowDropAsync(data).Forget();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 567ca35279f741d79f25e6d04bda5a63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,63 @@
using SepCore.Definition;
using SepCore.Entity;
using SepCore.Event;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace SepCore.Battle
{
public readonly struct HarvestSettlementResult
{
public static readonly HarvestSettlementResult Empty = new(0, 0, 0);
public int Income { get; }
public int Growth { get; }
public int NewHarvest { get; }
public HarvestSettlementResult(int income, int growth, int newHarvest)
{
Income = income;
Growth = growth;
NewHarvest = newHarvest;
}
}
public static class HarvestSettlementUtility
{
public const float HarvestCompoundRate = 0.05f;
public const string HarvestModifierSource = "HarvestInterest";
public static HarvestSettlementResult Settle(Player player)
{
if (player == null || !player.Available)
{
return HarvestSettlementResult.Empty;
}
int currentHarvest = Mathf.FloorToInt(player.StatComponent.GetStatValue(StatType.Harvesting));
if (currentHarvest <= 0)
{
return HarvestSettlementResult.Empty;
}
// 1. 发放等额金币/材料
player.Coin += currentHarvest;
// 2. 复合增长(利息):永久提升 5%(向上取整)
int growth = Mathf.CeilToInt(currentHarvest * HarvestCompoundRate);
if (growth > 0)
{
player.StatComponent.AddModifier(
StatType.Harvesting,
new StatModifier(growth, ModifierType.Flat, HarvestModifierSource));
}
int newHarvest = Mathf.FloorToInt(player.StatComponent.GetStatValue(StatType.Harvesting));
// 3. 广播收获结算事件
GameEntry.Event.Fire(player, WaveHarvestSettlementEventArgs.Create(currentHarvest, growth, newHarvest));
return new HarvestSettlementResult(currentHarvest, growth, newHarvest);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 193a30e24142468791b5c899b31ccae8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: