Explorar o código

修改事件表

lzx hai 3 semanas
pai
achega
429ed8df97

+ 3 - 2
Assets/Res/Config/DivineSenseConfig.json

@@ -4,8 +4,9 @@
       "ID": 1,
       "DetectEventCount": 3,
       "QualityBonusChance": 10,
-      "DivineSenseCount": 10,
-      "DivineSenseCost": 5
+      "DivineSenseCount": 100,
+      "DivineSenseCost": 5,
+      "MinDivineSenseValue": 100
     }
   ]
 }

+ 30 - 0
Assets/Res/Config/DivineSenseIntervalConfig.json

@@ -0,0 +1,30 @@
+{
+  "configList": [
+    {
+      "ID": 1,
+      "MinValue": 100,
+      "MaxValue": 300,
+      "EventQualities": [
+        1
+      ]
+    },
+    {
+      "ID": 2,
+      "MinValue": 300,
+      "MaxValue": 700,
+      "EventQualities": [
+        1,
+        2
+      ]
+    },
+    {
+      "ID": 3,
+      "MinValue": 700,
+      "MaxValue": 1000,
+      "EventQualities": [
+        2,
+        3
+      ]
+    }
+  ]
+}

+ 7 - 0
Assets/Res/Config/DivineSenseIntervalConfig.json.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: CH4Xt3utBnIKTnaQH1TVlShlVW72gEy0MgAkQSS9kA80aEC9PXdlgQL2ra9e
+TextScriptImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 2
Assets/Res/Config/EventConfig.json

@@ -3,8 +3,11 @@
     {
       "ID": 1,
       "EventType": 1,
+      "EventTriggerType": 1,
       "EventQuality": 1,
-      "EventConditionId": 2,
+      "EventConditionId": [
+        2
+      ],
       "EventVlaue": [
         2
       ],
@@ -23,8 +26,11 @@
     {
       "ID": 2,
       "EventType": 2,
+      "EventTriggerType": 1,
       "EventQuality": 1,
-      "EventConditionId": 1,
+      "EventConditionId": [
+        1
+      ],
       "EventVlaue": [
         5
       ],

+ 8 - 2
Assets/Scripts/GameData/ExcelConfig/DivineSenseConfig.cs

@@ -27,13 +27,13 @@ public int DetectEventCount;
 
 
 		/// <summary>
-		///高品质加成概率
+		///高品质加成概率(目前是线性增长)
 		/// </summary>
 public int QualityBonusChance;
 
 
 		/// <summary>
-		///每多少神识点提高概率
+		///触发额外权重乘数的步长(例如每100神识值)
 		/// </summary>
 public int DivineSenseCount;
 
@@ -44,6 +44,12 @@ public int DivineSenseCount;
 public int DivineSenseCost;
 
 
+		/// <summary>
+		///探索所需最低神识值
+		/// </summary>
+public int MinDivineSenseValue;
+
+
 	}
 
 }

+ 44 - 0
Assets/Scripts/GameData/ExcelConfig/DivineSenseIntervalConfig.cs

@@ -0,0 +1,44 @@
+// Auto Generated Code By excel2json
+// Generate From Excel\DivineSenseConfig.xlsx. SheetName: DivineSenseIntervalConfig
+
+using System;
+using Fort23.GameData;
+
+namespace Excel2Json
+{
+	[Config(prefab = "DivineSenseIntervalConfig.json")]
+	public partial class DivineSenseIntervalConfigHolder : ConfigHolder<DivineSenseIntervalConfig>
	{
+	}
+
+
+	[Serializable]
+	public struct DivineSenseIntervalConfig : IConfig
	{
+		public int GetID() {return ID;} 
+		/// <summary>
+		///ID
+		/// </summary>
+public int ID;
+
+
+		/// <summary>
+		///神识值区间下界(包含
+		/// </summary>
+public int MinValue;
+
+
+		/// <summary>
+		///神识值区间上界(不包含)
+		/// </summary>
+public int MaxValue;
+
+
+		/// <summary>
+		///允许的通用事件品质
+		/// </summary>
+public int[] EventQualities;
+
+
+	}
+
+}
+// End of Auto Generated Code

+ 11 - 0
Assets/Scripts/GameData/ExcelConfig/DivineSenseIntervalConfig.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: B3hL5n6vBnOYmVXzDk1CqwQR+iPVg+YYCwmwrSxvEN6LfAAyIYqDhsU5FRNl
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 7 - 1
Assets/Scripts/GameData/ExcelConfig/EventConfig.cs

@@ -26,6 +26,12 @@ public int ID;
 public int EventType;
 
 
+		/// <summary>
+		///触发事件类型: 1.场景事件 2.随机事件 3.通用事件
+		/// </summary>
+public int EventTriggerType;
+
+
 		/// <summary>
 		///事件品质
 		/// </summary>
@@ -35,7 +41,7 @@ public int EventQuality;
 		/// <summary>
 		///触发条件类型
 		/// </summary>
-public int EventConditionId;
+public int[] EventConditionId;
 
 
 		/// <summary>

+ 8 - 0
Assets/Scripts/GameLogic/EventManager.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: CSlJ5CmsACmY6Q5x2J/g1AsnnUAWK9CoP4lzacd4aPRvsZtkaVN/zmGw23xQ
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 87 - 0
Assets/Scripts/GameLogic/EventManager/DialogueManager.cs

@@ -0,0 +1,87 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Excel2Json;
+using Fort23.UTool;
+using UnityEngine;
+using Utility;
+
+
+public class DialogueManager : Singleton<DialogueManager>
+{
+    private readonly EventSystemManager eventManager;
+
+    private int currentDialogueID;
+    private int currentNodeID;
+    private int currentEventID;
+
+    private List<DialogueConfig> dialogueConfigs;
+    private List<DialogueOptionConfig> dialogueOptionConfigs;
+
+
+    public void CustomInit()
+    {
+        dialogueConfigs = ConfigComponent.Instance.GetAll<DialogueConfig>().ToList();
+        dialogueOptionConfigs = ConfigComponent.Instance.GetAll<DialogueOptionConfig>().ToList();
+    }
+
+    /// <summary>
+    /// 开始对话
+    /// </summary>
+    public void StartDialogue(int dialogueID, int eventID)
+    {
+        currentDialogueID = dialogueID;
+        currentNodeID = 1;
+        currentEventID = eventID;
+        ShowDialogue();
+    }
+
+    /// <summary>
+    /// 显示当前对话
+    /// </summary>
+    private void ShowDialogue()
+    {
+        //找到当前对话组
+        var dialogueConfig = dialogueConfigs.Find(n =>
+            n.ID == currentDialogueID && n.GroupId == currentNodeID);
+        if (dialogueConfig.ID == 0)
+        {
+            EndDialogue();
+            return;
+        }
+
+
+        //todo 加载对话ui
+    }
+
+    /// <summary>
+    /// 处理选项选择,跳转节点或触发逻辑。
+    /// </summary>
+    /// <param name="optionID">选项ID</param>
+    public void SelectOption(int optionID)
+    {
+        var option = dialogueOptionConfigs.Find(o => o.ID == optionID);
+        if (option.ID == 0)
+        {
+            EndDialogue();
+            return;
+        }
+
+        if (option.DialogueConfigID > 0)
+        {
+            currentNodeID = option.DialogueConfigID;
+            ShowDialogue();
+        }
+        else
+        {
+            EndDialogue();
+        }
+    }
+
+    /// <summary>
+    /// 结束对话
+    /// </summary>
+    private void EndDialogue()
+    {
+    }
+}

+ 11 - 0
Assets/Scripts/GameLogic/EventManager/DialogueManager.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: XC4WsC2pVijn26puLIgY33haYoRyIrmQsuOh1rOc7P8ZhZY8DS5JZTGn/BGZ
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 212 - 0
Assets/Scripts/GameLogic/EventManager/EventManager.cs

@@ -0,0 +1,212 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using Excel2Json;
+using Fort23.UTool;
+using UnityEngine;
+using Utility;
+
+public class EventSystemManager : Singleton<EventSystemManager>
+{
+    List<EventConfig> eventConfigs = new List<EventConfig>();
+    private List<DivineSenseIntervalConfig> divineSenseIntervalConfigs = new List<DivineSenseIntervalConfig>();
+
+    public void CustomInit()
+    {
+        eventConfigs = ConfigComponent.Instance.GetAll<EventConfig>().ToList();
+        divineSenseIntervalConfigs = ConfigComponent.Instance.GetAll<DivineSenseIntervalConfig>().ToList();
+    }
+
+
+    public void DetectEvents(int bigMapId)
+    {
+        BigMap bigMap = ConfigComponent.Instance.Get<BigMap>(bigMapId);
+        DivineSenseConfig divineSenseConfig = ConfigComponent.Instance.Get<DivineSenseConfig>(1);
+
+        // 选择神识区间
+        DivineSenseIntervalConfig interval = SelectInterval(200);
+
+        // 获取通用事件
+        List<EventConfig> globalEvents = eventConfigs
+            .Where(e => e.EventTriggerType == 3 && CanTriggerEvent(e.ID) &&
+                        interval.EventQualities.Contains(e.EventQuality))
+            .ToList();
+
+
+        //获取特定事件
+        var eventIDs = bigMap.DivineSenseEvent.ToList();
+        List<EventConfig> candidateEvents = eventConfigs
+            .Where(e => eventIDs.Contains(e.ID) && CanTriggerEvent(e.ID))
+            .ToList();
+        candidateEvents.AddRange(globalEvents);
+
+        if (candidateEvents.Count == 0)
+        {
+            LogTool.Warning("没有可以刷新的任务");
+            return;
+        }
+
+        // 计算高品质事件加成
+        float qualityBonusMultiplier = divineSenseConfig.QualityBonusChance *
+                                       Mathf.Floor((200 - divineSenseConfig.MinDivineSenseValue) /
+                                                   divineSenseConfig.DivineSenseCount);
+
+
+        // 获得全部权重
+        var eventWeights = new List<(EventConfig Event, int Weight)>();
+        float totalProbability = candidateEvents.Sum(evt =>
+        {
+            float prob = evt.BaseProbability;
+            if (evt.EventQuality >= 2)
+                prob *= (1f + qualityBonusMultiplier);
+            return prob;
+        });
+
+        foreach (var evt in candidateEvents)
+        {
+            float probability = evt.BaseProbability;
+            if (evt.EventQuality >= 2)
+                probability *= (1f + qualityBonusMultiplier);
+            int weight = Mathf.Max(1, Mathf.RoundToInt(probability / totalProbability * 100));
+            eventWeights.Add((evt, weight));
+        }
+
+
+        // 调整权重确保总和=100
+        int totalWeight = 100;
+        int currentSum = eventWeights.Sum(ew => ew.Weight);
+        if (currentSum != totalWeight)
+        {
+            float scale = (float)totalWeight / currentSum;
+            eventWeights = eventWeights.Select(ew => (ew.Event, Mathf.Max(1, Mathf.RoundToInt(ew.Weight * scale))))
+                .ToList();
+            // 微调总和
+            currentSum = eventWeights.Sum(ew => ew.Weight);
+            if (currentSum != totalWeight)
+            {
+                int diff = totalWeight - currentSum;
+                var maxWeightEvent = eventWeights.OrderByDescending(ew => ew.Weight).First();
+                eventWeights[eventWeights.IndexOf(maxWeightEvent)] =
+                    (maxWeightEvent.Event, maxWeightEvent.Weight + diff);
+            }
+        }
+
+
+        foreach (var (evt, weight) in eventWeights)
+        {
+            LogTool.Log($"EventId {evt.ID}: 权重={weight} ({weight / (float)totalWeight:P2})");
+        }
+
+        // 随机抽取事件
+        var triggeredEvents = new List<EventConfig>();
+        for (int i = 0; i < divineSenseConfig.DetectEventCount && eventWeights.Count > 0; i++)
+        {
+            int randomValue = UnityEngine.Random.Range(0, 101);
+            int cumulative = 0;
+            foreach (var (evt, weight) in eventWeights.ToList())
+            {
+                cumulative += weight;
+                if (randomValue < cumulative)
+                {
+                    triggeredEvents.Add(evt);
+                    eventWeights.RemoveAll(ew => ew.Event.ID == evt.ID);
+                    LogTool.Log($"S旋转事件 {evt.ID}, 权重={weight}, 随机到的权重={randomValue}");
+                    break;
+                }
+            }
+        }
+
+
+        // 触发事件
+        foreach (var evt in triggeredEvents)
+        {
+            TriggerEvent(evt);
+        }
+
+        if (triggeredEvents.Count == 0)
+        {
+            Debug.Log("没有可以触发的事件");
+        }
+    }
+
+    /// <summary>
+    /// 根据神识值选择通用神识区间
+    /// </summary>
+    private DivineSenseIntervalConfig SelectInterval(float divineSenseValue)
+    {
+        var intervals = divineSenseIntervalConfigs
+            .Where(i => divineSenseValue >= i.MinValue && divineSenseValue < i.MaxValue)
+            .ToList();
+        return intervals.FirstOrDefault();
+    }
+
+    /// <summary>
+    /// 触发单个事件,处理对话、奖励和完成逻辑。
+    /// </summary>
+    public void TriggerEvent(EventConfig evt)
+    {
+        Debug.Log($"触发事件: {evt.Description} (ID: {evt.ID}, 品质: {evt.EventQuality})");
+        if (evt.DialogueID > 0)
+        {
+            DialogueManager.Instance.StartDialogue(evt.DialogueID, evt.ID);
+        }
+
+        if (evt.RewardID.Length > 0)
+        {
+            // TODO: 实现奖励逻辑
+        }
+
+        CompleteEvent(evt.ID);
+    }
+
+    /// <summary>
+    /// 检查事件是否满足触发条件。
+    /// </summary>
+    private bool CanTriggerEvent(int eventID)
+    {
+        var evt = eventConfigs.Find(e => e.ID == eventID);
+        if (evt.ID == 0)
+            return false;
+
+
+        for (var i = 0; i < evt.EventConditionId.Length; i++)
+        {
+            if (!CheckCondition(evt.EventConditionId[i], evt.EventVlaue[i]))
+                return false;
+        }
+
+        return true;
+    }
+
+    /// <summary>
+    /// 检查单个触发条件。
+    /// </summary>
+    private bool CheckCondition(int conditionid, int EventVlaue)
+    {
+        //>=
+        if (EventVlaue == 1)
+        {
+        }
+        //=
+        else if (EventVlaue == 2)
+        {
+        }
+        // <=
+        else if (EventVlaue == 3)
+        {
+        }
+
+
+        return false;
+    }
+
+    /// <summary>
+    /// 完成任务
+    /// </summary>
+    /// <param name="eventID">事件ID</param>
+    public void CompleteEvent(int eventID)
+    {
+        LogTool.Log($"完成任务{eventID}");
+    }
+}

+ 11 - 0
Assets/Scripts/GameLogic/EventManager/EventManager.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: Di9K5H+tBilXP5VcUl204bQLyBo6vHDxH1FHFRtrwIUNzxkNOvzyyFSBTL/W
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN=BIN
Excel2Json/Excel/DivineSenseConfig.xlsx


BIN=BIN
Excel2Json/Excel/EventConfig.xlsx


BIN=BIN
Excel2Json/Excel/Maps.xlsx