3DMGAME 3DM首页 新闻中心 前瞻 | 评测 游戏库 热门 | 最新 攻略中心 攻略 | 秘籍 下载中心 游戏 | 汉化 购买正版 论坛

注册 登录

QQ登录

只需一步,快速开始

查看: 1885|回复: 3
打印 上一主题 下一主题

[攻略] 关于灵气是产生的具体流程 大神帮翻译一下这个代码

[复制链接]

6

主题

33

帖子

122

积分

中级玩家

Rank: 3Rank: 3

贡献度
0
金元
1219
积分
122
精华
0
注册时间
2015-12-14
跳转到指定楼层
主题
发表于 2020-1-8 20:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
没有编程基础 看代码实在是一头雾水 大神帮看看灵气产生的具体过程


using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
using XiaWorld.SaveLoad;

namespace XiaWorld
{
        // Token: 0x020002F4 RID: 756
        [JsonObject(MemberSerialization.OptIn)]
        public class LingMapData : SLClassDataAddion<SL_LingData>
        {
                // Token: 0x1700016B RID: 363
                // (get) Token: 0x060011C6 RID: 4550 RVA: 0x0008F188 File Offset: 0x0008D588
                private Map map
                {
                        get
                        {
                                if (this._map == null)
                                {
                                        this._map = World.Instance.map;
                                }
                                return this._map;
                        }
                }

                // Token: 0x060011C7 RID: 4551 RVA: 0x0008F1AB File Offset: 0x0008D5AB
                public void Init(int w, int h)
                {
                        this.m_cLQ = new GridManagerEx<LingMapData.LQData>();
                }

                // Token: 0x060011C8 RID: 4552 RVA: 0x0008F1B8 File Offset: 0x0008D5B8
                public List<int> GetAllLing()
                {
                        return this.m_cLQ.GetExistDataKeys();
                }

                // Token: 0x060011C9 RID: 4553 RVA: 0x0008F1C5 File Offset: 0x0008D5C5
                public void Step(float dt)
                {
                }

                // Token: 0x060011CA RID: 4554 RVA: 0x0008F1C8 File Offset: 0x0008D5C8
                public float GetLing(int key)
                {
                        LingMapData.LQData gridData = this.m_cLQ.GetGridData(key, null);
                        if (gridData == null)
                        {
                                return 0f;
                        }
                        return gridData.Value;
                }

                // Token: 0x060011CB RID: 4555 RVA: 0x0008F1F8 File Offset: 0x0008D5F8
                public void RemoveLingSource(int id)
                {
                        List<int> list = this.m_mapSource[id];
                        for (int i = 0; i < list.Count; i++)
                        {
                                int key = list[i];
                                LingMapData.LQData gridData = this.m_cLQ.GetGridData(key, null);
                                gridData.issource = false;
                        }
                }

                // Token: 0x060011CC RID: 4556 RVA: 0x0008F248 File Offset: 0x0008D648
                public void AddLing(int key, float v)
                {
                        LingMapData.LQData lqdata = this.m_cLQ.GetGridData(key, null);
                        if (lqdata == null)
                        {
                                lqdata = new LingMapData.LQData();
                                this.m_cLQ.SetGridData(key, lqdata);
                        }
                        if (!lqdata.issource)
                        {
                                lqdata.Value += v;
                        }
                }

                // Token: 0x060011CD RID: 4557 RVA: 0x0008F298 File Offset: 0x0008D698
                public int AddLingSource(List<int> keys, float value)
                {
                        this.m_mapSource[++this.mid] = keys;
                        for (int i = 0; i < keys.Count; i++)
                        {
                                int num = keys[i];
                                int num2;
                                int num3;
                                GridMgr.Inst.Key2P(num, out num2, out num3);
                                num2 /= this.scale;
                                num3 /= this.scale;
                                num = GridMgr.Inst.P2Key(num2, num3, false);
                                LingMapData.LQData lqdata = this.m_cLQ.GetGridData(num, null);
                                if (lqdata == null)
                                {
                                        lqdata = new LingMapData.LQData();
                                        this.m_cLQ.SetGridData(num, lqdata);
                                }
                                lqdata.Value = value;
                                lqdata.SValue = value;
                                lqdata.issource = true;
                        }
                        return this.mid;
                }

                // Token: 0x060011CE RID: 4558 RVA: 0x0008F360 File Offset: 0x0008D760
                public void UpdateLQ(float dt, int Count = 100, bool justdraw = false)
                {
                        if (GameMain.Instance.TeachMode && this.fristShow)
                        {
                                return;
                        }
                        this.m_fUpdateTime += dt;
                        for (int i = 0; i < Count; i++)
                        {
                                this.curPoint++;
                                if (this.curPoint >= GridMgr.Inst.GridCount)
                                {
                                        this.m_fLastUpdateTime = this.m_fUpdateTime;
                                        this.m_fUpdateTime = 0f;
                                        this.curPoint = -1;
                                        this.lingLoop++;
                                        break;
                                }
                                this.UpdateLingUnit(this.curPoint, false, 1f, justdraw);
                        }
                        if (this.curPoint == -1)
                        {
                                this.m_lisNpcGetLing.Clear();
                                this.fristShow = true;
                                MapRender.Instance.GetLingTex().Apply();
                        }
                }

                // Token: 0x060011CF RID: 4559 RVA: 0x0008F43C File Offset: 0x0008D83C
                public void UpdateAll(bool justmake, float scale = 1f)
                {
                        List<int> existDataKeys = this.m_cLQ.GetExistDataKeys();
                        int[] array = new int[existDataKeys.Count];
                        existDataKeys.CopyTo(array);
                        foreach (int dkey in array)
                        {
                                this.UpdateLingUnit(dkey, justmake, 1f, false);
                        }
                }

                // Token: 0x060011D0 RID: 4560 RVA: 0x0008F498 File Offset: 0x0008D898
                private void UpdateLingUnit(int dkey, bool justmake = false, float scale = 1f, bool justdraw = false)
                {
                        LingMapData.LQData gridData = this.m_cLQ.GetGridData(dkey, null);
                        if (gridData == null)
                        {
                                return;
                        }
                        if (!justdraw)
                        {
                                if (!gridData.issource || gridData.SValue < gridData.Value)
                                {
                                        if (gridData.Value < 2500f)
                                        {
                                                gridData.Value = Mathf.Min(gridData.Value - 0.1f, gridData.Value * 0.99f);
                                        }
                                        else
                                        {
                                                float f = gridData.Value / 2500f;
                                                float p = -0.82390875f;
                                                float num = 0.99f * Mathf.Pow(f, p);
                                                gridData.Value = num * gridData.Value;
                                        }
                                        if (gridData.Value < 0f)
                                        {
                                                gridData.Value = 0f;
                                        }
                                }
                                float num2 = gridData.Value - Mathf.Max(0f, this.map.Effect.GetEffect(dkey, g_emMapEffectKind.LingAddion, 0f, true));
                                if (num2 < 1f)
                                {
                                        return;
                                }
                                List<int> neighbor = GridMgr.Inst.GetNeighbor(dkey);
                                for (int i = 0; i < neighbor.Count; i++)
                                {
                                        int num3 = neighbor[i];
                                        LingMapData.LQData lqdata = this.m_cLQ.GetGridData(num3, null);
                                        if (lqdata == null)
                                        {
                                                lqdata = new LingMapData.LQData();
                                                this.m_cLQ.SetGridData(num3, lqdata);
                                        }
                                        float num4 = lqdata.Value - this.map.Effect.GetEffect(num3, g_emMapEffectKind.LingAddion, 0f, true);
                                        if (num4 < num2)
                                        {
                                                float num5 = 0f;
                                                float num6 = num2 - num4;
                                                if (num6 >= 15.6f)
                                                {
                                                        num5 = num6 / 1.3f;
                                                }
                                                else if (num6 >= 2.4f)
                                                {
                                                        num5 = num6 / 1.6f;
                                                }
                                                else if (num6 >= 1.8f)
                                                {
                                                        num5 = Mathf.Pow(2f, num6 * 5f - 10f) / 5f;
                                                }
                                                else if (num6 >= 0.4f)
                                                {
                                                        num5 = 0.2f;
                                                }
                                                else
                                                {
                                                        num5 = 0f;
                                                }
                                                num5 *= scale;
                                                float num7 = 0f;
                                                float num8 = 0f;
                                                if (!justmake)
                                                {
                                                        float num9 = lqdata.Value;
                                                        List<Thing> thingsAtGrid = this.map.Things.GetThingsAtGrid(num3);
                                                        if (thingsAtGrid != null)
                                                        {
                                                                foreach (Thing thing in thingsAtGrid)
                                                                {
                                                                        if (thing != null && thing.def != null && thing.AtG && thing.Attenuation > 0f && thing.Absorption > 0f && thing.Accommodate > 0f && thing.IsValid && thing.CheckWorkingAfterPutdown())
                                                                        {
                                                                                num7 += thing.Attenuation;
                                                                                if (num9 > 0f)
                                                                                {
                                                                                        float num10 = Mathf.Min(num9, Mathf.Max(num9 - thing.LingV / thing.Accommodate, (float)thing.TempRate) * thing.Absorption * 0.004f);
                                                                                        num9 -= num10;
                                                                                        num8 += num10;
                                                                                        thing.AddLing(num10, 0);
                                                                                        thing.RecordAddLingByLingMap(num10, this.lingLoop);
                                                                                }
                                                                                float num11 = num5 * thing.Attenuation * thing.Absorption * 0.01f;
                                                                                thing.AddLing(num11, 0);
                                                                                thing.RecordAddLingByLingMap(num11, this.lingLoop);
                                                                        }
                                                                }
                                                        }
                                                        List<Npc> npcByKey = this.map.Things.GetNpcByKey(num3);
                                                        if (npcByKey != null)
                                                        {
                                                                foreach (Npc npc in npcByKey)
                                                                {
                                                                        if (npc.IsAbsorbLing && num9 > 0f && (npc.Rank == g_emNpcRank.Disciple || npc.CheckSpecialFlag(g_emNpcSpecailFlag.FLAG_ADDTIONLINGMAX) > 0) && !npc.IsDeath && !npc.HasSpecialFlag(g_emNpcSpecailFlag.FLAG_NOLING) && !this.m_lisNpcGetLing.Contains(npc.ID))
                                                                        {
                                                                                this.m_lisNpcGetLing.Add(npc.ID);
                                                                                g_emElementKind kind = g_emElementKind.None;
                                                                                if (npc.IsDisciple)
                                                                                {
                                                                                        kind = npc.PropertyMgr.Practice.Gong.ElementKind;
                                                                                }
                                                                                float num12 = Mathf.Max(num9 * Mathf.Lerp(1f, 3f, npc.map.GetElementPower(npc.Key, kind) / 4f + 0.5f) / 40f, 0f);
                                                                                num12 *= npc.GetProperty("LingAbsorbSpeed");
                                                                                num12 *= 4f;
                                                                                if (num12 >= 0f)
                                                                                {
                                                                                        num9 -= num12;
                                                                                        num8 += num12;
                                                                                        npc.DynamicAddLing(num12 / 16f + npc.MaxLing * 0.0002f);
                                                                                }
                                                                        }
                                                                }
                                                        }
                                                        TerrainDef terrain = this.map.Terrain.GetTerrain(num3);
                                                        if (terrain.Attenuation > 0f)
                                                        {
                                                                num7 += terrain.Attenuation;
                                                        }
                                                }
                                                lqdata.Value = Mathf.Max(0f, lqdata.Value + num5 * Mathf.Max(1f - num7, 0f) - num8);
                                        }
                                }
                        }
                        if (!justmake && (!this.fristShow || this.map.IsInLight(dkey)))
                        {
                                float ling = this.map.GetLing(dkey);
                                Color clear = Color.clear;
                                int x;
                                int y;
                                GridMgr.Inst.Key2P(dkey, out x, out y);
                                clear.a = Mathf.Min(200f, ling) / 500f;
                                MapRender.Instance.GetLingTex().SetPixel(x, y, clear);
                        }
                }

                // Token: 0x060011D1 RID: 4561 RVA: 0x0008FAE0 File Offset: 0x0008DEE0
                public void UpdateRender(bool clear = false)
                {
                        if (clear)
                        {
                                MapRender.Instance.GetTilemap(g_emTileMapType.Ling).IsVisible = false;
                                return;
                        }
                        MapRender.Instance.UpdateLingTex();
                        MapRender.Instance.GetTilemap(g_emTileMapType.Ling).IsVisible = true;
                }

                // Token: 0x060011D2 RID: 4562 RVA: 0x0008FB18 File Offset: 0x0008DF18
                public override SL_LingData GetSaveData()
                {
                        SL_LingData sl_LingData = new SL_LingData();
                        sl_LingData.Size = this.map.Size;
                        List<int> existDataKeys = this.m_cLQ.GetExistDataKeys();
                        foreach (int num in existDataKeys)
                        {
                                LingMapData.LQData gridData = this.m_cLQ.GetGridData(num, null);
                                if (gridData != null)
                                {
                                        if (gridData.issource)
                                        {
                                                sl_LingData.Source.Add(num);
                                        }
                                        sl_LingData.Value.Add(new int[]
                                        {
                                                num,
                                                (int)gridData.Value,
                                                (int)gridData.SValue
                                        });
                                }
                        }
                        return sl_LingData;
                }

                // Token: 0x060011D3 RID: 4563 RVA: 0x0008FBE8 File Offset: 0x0008DFE8
                public int GetMaxPoint()
                {
                        List<int> existDataKeys = this.m_cLQ.GetExistDataKeys();
                        float num = -999999f;
                        int result = 0;
                        foreach (int num2 in existDataKeys)
                        {
                                float ling = this.map.GetLing(num2);
                                if (ling > num)
                                {
                                        num = ling;
                                        result = num2;
                                }
                        }
                        return result;
                }

                // Token: 0x060011D4 RID: 4564 RVA: 0x0008FC6C File Offset: 0x0008E06C
                public override void LoadSaveData(SL_LingData data)
                {
                        this.Init(data.Size, data.Size);
                        foreach (int[] array in data.Value)
                        {
                                int num = array[1];
                                int num2 = array[0];
                                if (num > 0)
                                {
                                        LingMapData.LQData lqdata = new LingMapData.LQData();
                                        if (num > 2500)
                                        {
                                                num = 2500;
                                        }
                                        lqdata.Value = (float)num;
                                        if (data.Source.Contains(num2))
                                        {
                                                lqdata.issource = true;
                                        }
                                        if (lqdata.issource)
                                        {
                                                if (array.Length > 3)
                                                {
                                                        lqdata.SValue = (float)array[2];
                                                }
                                                else
                                                {
                                                        lqdata.SValue = (float)Mathf.Min(num, 200);
                                                }
                                        }
                                        this.m_cLQ.SetGridData(num2, lqdata);
                                }
                        }
                }

                // Token: 0x060011D5 RID: 4565 RVA: 0x0008FD64 File Offset: 0x0008E164
                public void AfterLoad()
                {
                        this.UpdateLQ(0f, 9999999, true);
                }

                // Token: 0x04001162 RID: 4450
                private Map _map;

                // Token: 0x04001163 RID: 4451
                private int scale = 1;

                // Token: 0x04001164 RID: 4452
                public GridManagerEx<LingMapData.LQData> m_cLQ;

                // Token: 0x04001165 RID: 4453
                [JsonProperty]
                private Dictionary<int, List<int>> m_mapSource = new Dictionary<int, List<int>>();

                // Token: 0x04001166 RID: 4454
                [JsonProperty]
                private int mid;

                // Token: 0x04001167 RID: 4455
                private bool fristShow;

                // Token: 0x04001168 RID: 4456
                private List<int> m_lisNpcGetLing = new List<int>();

                // Token: 0x04001169 RID: 4457
                private int curPoint = -1;

                // Token: 0x0400116A RID: 4458
                private float m_fLastUpdateTime = 0.2f;

                // Token: 0x0400116B RID: 4459
                private float m_fUpdateTime;

                // Token: 0x0400116C RID: 4460
                private int lingLoop;

                // Token: 0x020002F5 RID: 757
                public class LQData
                {
                        // Token: 0x0400116D RID: 4461
                        public bool issource;

                        // Token: 0x0400116E RID: 4462
                        public float Value;

                        // Token: 0x0400116F RID: 4463
                        public float SValue;
                }
        }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|3DMGAME ( 京ICP备14006952号-1  沪公网安备 31011202006753号

GMT+8, 2026-3-26 17:25 , Processed in 0.029285 second(s), 16 queries , Memcached On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表