- 补充游戏核心逻辑

- 完成 TodOList P0
    - 添加游戏内控制台便于调试
    - 增加敌人互斥机制提高运算负载
    - 优化互斥算法将游戏性能基准线拉到 1k 敌人
This commit is contained in:
SepComet
2026-02-20 18:08:27 +08:00
parent b4bc8b0445
commit 3742110e9a
196 changed files with 4868 additions and 31326 deletions
@@ -1,12 +1,29 @@
using CustomEvent;
using Definition.Enum;
using GameFramework.Event;
using UnityGameFramework.Runtime;
namespace UI
{
public class DisplayItemInfoFormController : UIFormControllerCommonBase<DisplayItemInfoFormContext, DisplayItemInfoForm>
public class DisplayItemInfoFormController : UIFormControllerCommonBase<
DisplayItemInfoFormContext, DisplayItemInfoForm>
{
protected override UIFormType UIFormTypeId => UIFormType.DisplayItemInfoForm;
private bool _locked = false;
protected override void SubscribeCustomEvents()
{
GameEntry.Event.Subscribe(DisplayItemInfoLockEventArgs.EventId, DisplayItemInfoLock);
GameEntry.Event.Subscribe(DisplayItemInfoHideEventArgs.EventId, DisplayItemInfoHide);
}
protected override void UnsubscribeCustomEvents()
{
GameEntry.Event.Unsubscribe(DisplayItemInfoLockEventArgs.EventId, DisplayItemInfoLock);
GameEntry.Event.Unsubscribe(DisplayItemInfoHideEventArgs.EventId, DisplayItemInfoHide);
}
protected override void RefreshUI(DisplayItemInfoForm form, DisplayItemInfoFormContext context)
{
form.RefreshUI(context);
@@ -26,6 +43,7 @@ namespace UI
return new DisplayItemInfoFormContext
{
Index = rawData.Index,
IconAssetName = rawData.IconAssetName,
Title = rawData.Title,
Rarity = rawData.Rarity,
@@ -39,12 +57,14 @@ namespace UI
public int? OpenUI(DisplayItemInfoFormRawData rawData)
{
_locked = false;
DisplayItemInfoFormContext context = BuildContext(rawData);
return OpenUIInternal(context);
}
public override int? OpenUI(object userData = null)
{
_locked = false;
if (userData is DisplayItemInfoFormContext context)
{
return OpenUIInternal(context);
@@ -71,5 +91,26 @@ namespace UI
Log.Error("DisplayItemInfoForm.BindUseCase() useCase is invalid.");
}
}
#region Event Handlers
private void DisplayItemInfoLock(object sender, GameEventArgs e)
{
if (!(e is DisplayItemInfoLockEventArgs)) return;
_locked = true;
}
private void DisplayItemInfoHide(object sender, GameEventArgs e)
{
if (!(e is DisplayItemInfoHideEventArgs args)) return;
if (!args.Force && _locked && sender is not DisplayItemInfoForm) return;
GameEntry.UIRouter.CloseUI(UIFormType.DisplayItemInfoForm);
_locked = false;
}
#endregion
}
}
}
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using CustomEvent;
using Definition.Enum;
using Game.Utility;
using CustomUtility;
using GameFramework.Event;
using UnityGameFramework.Runtime;
@@ -49,6 +49,7 @@ namespace UI
{
Title = reward.Title,
Icon = null,
ItemRarity = reward.Rarity,
Description = ItemDescUtility.CreatePropDescription(reward.Modifiers),
IconAssetName = reward.IconAssetName
});
@@ -3,8 +3,10 @@ using CustomEvent;
using Definition.DataStruct;
using Definition.Enum;
using Entity;
using Game.Utility;
using CustomUtility;
using Entity.Weapon;
using GameFramework.Event;
using UnityEngine;
using UnityGameFramework.Runtime;
namespace UI
@@ -25,18 +27,18 @@ namespace UI
{
GameEntry.Event.Subscribe(RefreshEventArgs.EventId, Refresh);
GameEntry.Event.Subscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
GameEntry.Event.Subscribe(ShopWeaponRecycleEventArgs.EventId, WeaponRecycle);
GameEntry.Event.Subscribe(ShopContinueEventArgs.EventId, ShopContinue);
GameEntry.Event.Subscribe(DisplayItemShowEventArgs.EventId, DisplayItemShow);
GameEntry.Event.Subscribe(DisplayItemHideEventArgs.EventId, DisplayItemHide);
}
protected override void UnsubscribeCustomEvents()
{
GameEntry.Event.Unsubscribe(RefreshEventArgs.EventId, Refresh);
GameEntry.Event.Unsubscribe(ShopPurchaseEventArgs.EventId, ShopPurchase);
GameEntry.Event.Unsubscribe(ShopWeaponRecycleEventArgs.EventId, WeaponRecycle);
GameEntry.Event.Unsubscribe(ShopContinueEventArgs.EventId, ShopContinue);
GameEntry.Event.Unsubscribe(DisplayItemShowEventArgs.EventId, DisplayItemShow);
GameEntry.Event.Unsubscribe(DisplayItemHideEventArgs.EventId, DisplayItemHide);
}
#region BuildContext
@@ -56,12 +58,15 @@ namespace UI
RefreshPrice = rawData.RefreshPrice,
PlayerCoin = rawData.PlayerCoin,
GoodsItems = rawData.GoodsItems,
PropListContext = BuildDisplayListAreaContext(DisplayListAreaType.Prop, rawData.PropItems, rawData.PropMaxCount),
WeaponListContext = BuildDisplayListAreaContext(DisplayListAreaType.Weapon, rawData.WeaponItems, rawData.WeaponMaxCount)
PropListContext =
BuildDisplayListAreaContext(DisplayListAreaType.Prop, rawData.PropItems, rawData.PropMaxCount),
WeaponListContext = BuildDisplayListAreaContext(DisplayListAreaType.Weapon, rawData.WeaponItems,
rawData.WeaponMaxCount)
};
}
private static DisplayListAreaContext BuildDisplayListAreaContext(DisplayListAreaType listType, IReadOnlyList<object> items,
private static DisplayListAreaContext BuildDisplayListAreaContext(DisplayListAreaType listType,
IReadOnlyList<object> items,
int maxCount)
{
string title = GetDisplayListTitle(listType);
@@ -89,6 +94,7 @@ namespace UI
itemContexts[i] = BuildWeaponItem(weapon);
}
}
break;
case DisplayListAreaType.Prop:
@@ -101,6 +107,7 @@ namespace UI
itemContexts[i] = BuildPropItem(propItem);
}
}
break;
}
@@ -347,6 +354,7 @@ namespace UI
DisplayItemInfoFormRawData rawData = new();
rawData.TargetPos = args.TargetPos;
rawData.Index = args.Index;
if (args.IsWeapon)
{
var weaponData = _rawData.WeaponItems[args.Index].WeaponData;
@@ -355,7 +363,7 @@ namespace UI
rawData.Rarity = weaponData.Rarity;
rawData.TypeText = "武器";
rawData.Description = ItemDescUtility.CreateWeaponDescription(weaponData);
rawData.Price = 0;
rawData.Price = Mathf.FloorToInt(weaponData.Price * Context.WeaponRecycleRate);
rawData.IsWeapon = true;
}
else
@@ -373,11 +381,29 @@ namespace UI
GameEntry.UIRouter.OpenUI(UIFormType.DisplayItemInfoForm, rawData);
}
private void DisplayItemHide(object sender, GameEventArgs e)
private void WeaponRecycle(object sender, GameEventArgs e)
{
if (!(e is DisplayItemHideEventArgs)) return;
if (!(e is ShopWeaponRecycleEventArgs args)) return;
GameEntry.UIRouter.CloseUI(UIFormType.DisplayItemInfoForm);
if (_useCase == null || Context == null)
{
return;
}
bool success = _useCase.TryRecycleWeapon(args.Index, args.Price);
if (!success)
{
return;
}
if (Context.WeaponListContext != null)
{
int currentCount = Mathf.Max(0, Context.WeaponListContext.CurrentCount - 1);
Context.WeaponListContext.CurrentCount = currentCount;
}
Form?.RemoveWeaponDisplayItem(args.Index);
GameEntry.Event.Fire(this, DisplayItemInfoHideEventArgs.Create(true));
}
#endregion