Coder Social home page Coder Social logo

taiwu-mods's People

Contributors

leaf3woods avatar

Stargazers

 avatar  avatar

Watchers

 avatar

taiwu-mods's Issues

成功生成调用特质池子,但最终角色无基础特征

这是一个GameData.Domains.Character.Character 下 GenerateRandomBasicFeatures的前置补丁

[HarmonyPrefix]
[HarmonyPatch(declaringType: typeof(GameData.Domains.Character.Character), methodName: "GenerateRandomBasicFeatures")]
public static bool PrefixOfGenerateRandomBasicFeatures(bool isProtagonist, Dictionary<short, short> featureGroup2Id)

featureGroup2Id 应该会以引用传递进我的补丁,在打印的log中看到 featureGroup2Id 已成功加入了自定义特征池子中的随机特征

AdaptableLog.Info("feature add Succeed! detail:" + string.Join(",", featureGroup2Id.Values));
return false;

可最终已加入 featureGroup2Id 中的特征并未生效,效果是角色的所有基础特征全部丢失

prefix部分完整代码

[HarmonyPrefix]
[HarmonyPatch(declaringType: typeof(GameData.Domains.Character.Character), methodName: "GenerateRandomBasicFeatures")]
public static bool PrefixOfGenerateRandomBasicFeatures(bool isProtagonist, Dictionary<short, short> featureGroup2Id)
{
    if (!isProtagonist) return true;
    try
    {
        AdaptableLog.Info($"current features's featId are {string.Join(",", featureGroup2Id.Values)}");
        var featureInstance = CharacterFeature.Instance;
        _config.AllAvailableFeatures = featureInstance.Select<CharacterFeatureItem, Feature>(x =>
        {
            return new Feature
            {
                Id = x.TemplateId,
                GroupId = x.MutexGroupId,
                Name = x.Name,
            };
        });
        var customFeatPool = _config.AllAvailableFeatures
            .Where(x => _config.CustomFeatures.Any(y => x.Id == y.Id))
            ?? throw new Exception("can't find available feature in custom feature pool!");
        var lockedFeatDic = customFeatPool
            .Where(x => x.IsLocked && !featureGroup2Id.Any(y => y.Key == x.Id))
            .ToDictionary(x => x.Id, x => x.GroupId)
            .Take(_config.FeaturesCount);
        featureGroup2Id = featureGroup2Id.Concat(lockedFeatDic).ToDictionary(x => x.Key, x => x.Value);
        AdaptableLog.Info($"get all({_config.AllAvailableFeatures.Count()})-custom({customFeatPool.Count()}) feats succeed");
        if (!_config.IsOriginPoolGen)
        {
            PatchConfig.SaveAsJson<IEnumerable<Feature>>(_config.AllAvailableFeatures, "available_features.json");
            //一个组必定都是基础属性
            PatchConfig.SaveAsJson<IEnumerable<Feature>>(_config.AllAvailableFeatures
                .Where(x => featureInstance[x.Id].Basic)
                , "available_basic_features.json");
            PatchConfig.SaveAsJson<IEnumerable<Feature>>(_config.AllAvailableFeatures
                .Where(x => featureInstance[x.Id].CandidateGroupId == 0)
                , "available_basic_positive_features.json");
            AdaptableLog.Info("generate origin pool succeed");
        }
        //减去消耗的基础属性数
        var customFeatureCount = _config.FeaturesCount - featureGroup2Id.Count(x => featureInstance[x.Value].Basic);
        var remainsCustomFeatPool = customFeatPool
            .Where(x => !featureGroup2Id.Any(y => y.Key == x.Id))
            .ToDictionary(x => x.Id, x => x.GroupId);
        AdaptableLog.Info($"remain custom features/pool count is {customFeatureCount}/{remainsCustomFeatPool.Count}");
        while (customFeatureCount > 0)
        {
            var radomFeature = GetRandomFeatureFromCustomPool(remainsCustomFeatPool);
            featureGroup2Id.Add(radomFeature.Item1, radomFeature.Item2);
            customFeatureCount--;
        }
        _config.IsOriginPoolGen = true;
        _config.SaveConfig();
        AdaptableLog.Info("feature add Succeed! detail:" + string.Join(",", featureGroup2Id.Values));
        return false;
    }
    catch(Exception ex)
    {
        AdaptableLog.Warning($"patching feature failed: " + ex.Message);
        return true;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.