You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
14 KiB
363 lines
14 KiB
// using System;
|
|
// using System.Collections.Generic;
|
|
// using GAS;
|
|
// using GAS.Runtime;
|
|
// using xFrame;
|
|
//
|
|
// namespace CoreGame.Render
|
|
// {
|
|
// public static class AbilitySrv
|
|
// {
|
|
// private static int s_SeqGen = 1;
|
|
//
|
|
// private static readonly Dictionary<int, GameplayAbility>
|
|
// s_AbilityAssets = new(300);
|
|
//
|
|
// private static readonly Dictionary<string, GameplayEffect>
|
|
// s_GameplayEffects = new(50);
|
|
//
|
|
// public static void AttachActiveAbilityGroup(int groupId, CombatEntity entity, int level = 1)
|
|
// {
|
|
// var tbSkillGroup = SkillGroupDescMgr.Instance.GetConfig(groupId);
|
|
// GrantBaseAbility(entity);
|
|
// AttachActiveAbility(entity, tbSkillGroup.defaultSkill);
|
|
// foreach (var skill in tbSkillGroup.skillA)
|
|
// {
|
|
// AttachActiveAbility(entity, skill);
|
|
// }
|
|
//
|
|
// foreach (var skill in tbSkillGroup.skillB)
|
|
// {
|
|
// AttachActiveAbility(entity, skill);
|
|
// }
|
|
//
|
|
// AttachActiveAbility(entity, tbSkillGroup.skillDeath);
|
|
// }
|
|
//
|
|
// public static GameAbilityContext AttachTalent_WithGaParam(CombatEntity entity, int talentId,
|
|
// CombatEntity granter, int level)
|
|
// {
|
|
// var talentDesc = TalentDescMgr.Instance.GetConfig(talentId);
|
|
// if (talentDesc == null)
|
|
// {
|
|
// XLog.LogWarning($"AttachTalent_WithGaParam: talent {talentId} is null");
|
|
// return null;
|
|
// }
|
|
//
|
|
// var skillIds = talentDesc.skillId;
|
|
// GameplayAbilityCfg gaCfg = default;
|
|
// // gaCfg.cleanOnDeactive = true; // 默认清理!!!
|
|
// gaCfg.p1 = talentDesc.desc[0].Num;
|
|
// gaCfg.p2 = talentDesc.desc[1].Num;
|
|
// gaCfg.p3 = talentDesc.desc[2].Num;
|
|
// gaCfg.p4 = talentDesc.desc[3].Num;
|
|
// // gaParam.param1 = talentDesc.desc;
|
|
// GameAbilityContext fristAbility = null;
|
|
// for (var index = 0; index < skillIds.Length; index++)
|
|
// {
|
|
// var skillId = skillIds[index];
|
|
// var attachActiveAbility = GrantTransferAbility(entity, skillId, gaCfg, granter, level);
|
|
// if (attachActiveAbility == null)
|
|
// continue;
|
|
//
|
|
// fristAbility ??= attachActiveAbility;
|
|
// // attachActiveAbility.abilitySpec.gaInitCfg = gaCfg;
|
|
// }
|
|
//
|
|
// return fristAbility;
|
|
// }
|
|
//
|
|
// public static GameAbilityContext GrantTransferAbility(CombatEntity entity, int abilityId,
|
|
// in GameplayAbilityCfg gaInitCfg, CombatEntity granter = null, int level = 1)
|
|
// {
|
|
// if (entity.IsValid() == false)
|
|
// {
|
|
// XLog.LogWarning("AttachActiveAbility : entity is null");
|
|
// return null;
|
|
// }
|
|
//
|
|
// if (entity.hasAbilitySystem == false)
|
|
// {
|
|
// entity.AddAbilitySystem(entity);
|
|
// entity.abilitySystem.Init(null, null, null, 1);
|
|
// // GrantBaseAbility(entity);
|
|
// #if !GAME_RELEASE
|
|
// GameplayAbilitySystem.GAS.Register(entity.abilitySystem);
|
|
// #endif
|
|
// }
|
|
//
|
|
// if (abilityId == 0)
|
|
// return null;
|
|
//
|
|
// var tbSkill = SkillDescMgr.Instance.GetConfig(abilityId);
|
|
// if (tbSkill == null)
|
|
// {
|
|
// XLog.LogWarning("GrantTransferAbility : tbSkill is null, abilityId is " + abilityId);
|
|
// return null;
|
|
// }
|
|
// // Asset属于配置表,不允许篡改
|
|
// var ability = GetAbility(tbSkill);
|
|
// GameAbilityContext gaCtx = null;
|
|
// if (ability != null)
|
|
// {
|
|
// // 需要在UnGrantAbility时释放
|
|
// gaCtx = SptPool<GameAbilityContext>.Malloc();
|
|
// gaCtx.ownerEnt = entity;
|
|
// if (granter != null)
|
|
// {
|
|
// gaCtx.granterEid = granter.creationIndex;
|
|
// }
|
|
//
|
|
// gaCtx.abilityId = abilityId;
|
|
// gaCtx.abilityCfg = tbSkill;
|
|
// gaCtx.gaSeq = s_SeqGen++;
|
|
// gaCtx.level = level;
|
|
// entity.abilitySystem.GrantAbility(ability, gaCtx, gaInitCfg);
|
|
// // XLog.LogDebug($"AttachActiveAbility: {tbSkill.SkillTemplatePath} {gaCtx.gaSeq}");
|
|
// }
|
|
// else
|
|
// {
|
|
// XLog.LogWarning($"AttachActiveAbility: ability {abilityId} level {level} is null");
|
|
// }
|
|
//
|
|
// return gaCtx;
|
|
// }
|
|
//
|
|
// public static GameAbilityContext AttachActiveAbility(CombatEntity entity, int abilityId,
|
|
// CombatEntity granter = null, int level = 1)
|
|
// {
|
|
// if (entity.IsValid() == false)
|
|
// {
|
|
// XLog.LogWarning("AttachActiveAbility : entity is null");
|
|
// return null;
|
|
// }
|
|
//
|
|
// if (entity.hasAbilitySystem == false)
|
|
// {
|
|
// entity.AddAbilitySystem(entity);
|
|
// entity.abilitySystem.Init();
|
|
// // GrantBaseAbility(entity);
|
|
// #if !GAME_RELEASE
|
|
// // GameplayAbilitySystem.GAS.Register(entity.abilitySystem);
|
|
// #endif
|
|
// }
|
|
//
|
|
// if (abilityId == 0)
|
|
// return null;
|
|
//
|
|
// var tbSkill = SkillDescMgr.Instance.GetConfig(abilityId);
|
|
// // Asset属于配置表,不允许篡改
|
|
// var ability = GetAbility(tbSkill);
|
|
// GameAbilityContext gaCtx = null;
|
|
// if (ability != null)
|
|
// {
|
|
// // 需要在UnGrantAbility时释放
|
|
// gaCtx = SptPool<GameAbilityContext>.Malloc();
|
|
// gaCtx.ownerEnt = entity;
|
|
// if (granter != null)
|
|
// {
|
|
// gaCtx.granterEid = granter.creationIndex;
|
|
// }
|
|
//
|
|
// gaCtx.abilityId = abilityId;
|
|
// gaCtx.abilityCfg = tbSkill;
|
|
// gaCtx.gaSeq = s_SeqGen++;
|
|
// gaCtx.level = level;
|
|
// entity.abilitySystem.GrantAbility(ability, gaCtx, default);
|
|
// // XLog.LogDebug($"AttachActiveAbility: {tbSkill.SkillTemplatePath} {gaCtx.gaSeq}");
|
|
// }
|
|
// else
|
|
// {
|
|
// XLog.LogWarning($"AttachActiveAbility: ability {abilityId} level {level} is null");
|
|
// }
|
|
//
|
|
// return gaCtx;
|
|
// }
|
|
//
|
|
// public static GameAbilityContext AttachAndTryActiveAbility(CombatEntity entity, int abilityId, bool dropAbility)
|
|
// {
|
|
// var context = AttachActiveAbility(entity, abilityId);
|
|
// if (context != null)
|
|
// {
|
|
// context.dropAbilityWhenEnd = dropAbility;
|
|
// context.asc.TryActivateAbility_WithSeq(context.gaSeq);
|
|
// }
|
|
//
|
|
// return context;
|
|
// }
|
|
//
|
|
// public static GameplayAbility GetAbility(SkillDesc cfg)
|
|
// {
|
|
// if (string.IsNullOrEmpty(cfg.SkillTemplatePath))
|
|
// return null;
|
|
//
|
|
//
|
|
// if (s_AbilityAssets.TryGetValue(cfg.id, out var ability) == false)
|
|
// {
|
|
// var asset = SyncAssetLoader.GetAssetObject<AbilityAsset>("AbilityAsset", cfg.SkillTemplatePath);
|
|
// if (asset == null)
|
|
// {
|
|
// XLog.LogWarning($"GetAbility: {cfg.SkillTemplatePath} is null or not an AbilityAsset");
|
|
// return null;
|
|
// }
|
|
//
|
|
// asset.abilityID = cfg.id;
|
|
// // switch (cfg.Id)
|
|
// ability = Activator.CreateInstance(asset.AbilityType(), args: asset) as GameplayAbility;
|
|
//
|
|
// if (asset is TimelineAbilityAssetBase timelineAbilityAsset)
|
|
// {
|
|
// timelineAbilityAsset.Init();
|
|
// }
|
|
//
|
|
// if (ability != null)
|
|
// {
|
|
// s_AbilityAssets.Add(cfg.id, ability);
|
|
//
|
|
// var abilityTagContainer = GameplayAbility.s_UseAssetTag
|
|
// ? ability.Tag
|
|
// : GetAbilityTagContainerFromSkillCfg(cfg);
|
|
// ability.SetTagContainer(ref abilityTagContainer);
|
|
// ability.NormalizeAssetsCooldownTime();
|
|
// }
|
|
// }
|
|
//
|
|
// return ability;
|
|
// }
|
|
//
|
|
// public static void GrantBaseAbility(CombatEntity entity)
|
|
// {
|
|
// var commParamDesc = CommParamDescMgr.Instance.GetConfig("DefaultGA");
|
|
// foreach (var abilityId in commParamDesc.int_list)
|
|
// {
|
|
// AttachActiveAbility(entity, abilityId); // 受击能力
|
|
// }
|
|
// }
|
|
//
|
|
// public static void DetachTalent(AbilitySystemComponent asc, int talentId)
|
|
// {
|
|
// var talentDesc = TalentDescMgr.Instance.GetConfig(talentId);
|
|
// for (int j = 0; j < talentDesc.skillId.Length; j++)
|
|
// {
|
|
// asc.UnGrantAbilityByCfgId(talentDesc.skillId[j]);
|
|
// }
|
|
// }
|
|
//
|
|
// public static void ResetTalentSkill(CombatEntity entity, List<TalentInfo> adds, List<TalentInfo> removes)
|
|
// {
|
|
// var abilitySystemComponent = entity.abilitySystem;
|
|
// if (abilitySystemComponent == null)
|
|
// {
|
|
// entity.AddAbilitySystem(entity);
|
|
// abilitySystemComponent = entity.abilitySystem;
|
|
// }
|
|
//
|
|
// if (removes != null)
|
|
// {
|
|
// for (int i = 0; i < removes.Count; i++)
|
|
// {
|
|
// XLog.LogDebug($"【remove talent】 is {removes[i].talentId}, level is {removes[i].level}");
|
|
// DetachTalent(abilitySystemComponent, removes[i].talentId);
|
|
// }
|
|
// }
|
|
//
|
|
// if (adds != null)
|
|
// {
|
|
// for (int i = 0; i < adds.Count; i++)
|
|
// {
|
|
// XLog.LogDebug($"【add talent】 is {adds[i].talentId}, level is {adds[i].level}");
|
|
// AttachTalent_WithGaParam(entity, adds[i].talentId, null, adds[i].level);
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// //
|
|
// if (entity.TagCountContainer.HasTag(GTagLib.CD_Solt_ChangeGunSkill))
|
|
// return;
|
|
//
|
|
// var hasAbility = entity.abilitySystem.AbilityContainer.HasAbility(GTagLib.Solt_ChangeGunSkill);
|
|
// if (hasAbility == false)
|
|
// return;
|
|
// if (entity.isLocalPlayer)
|
|
// {
|
|
// var cduiData = new CDUIData();
|
|
// cduiData.slot = 1;
|
|
// cduiData.type = CDUIType.ChangeGun;
|
|
// cduiData.lastCd = 0;
|
|
// cduiData.totalCd = 1f;
|
|
// EventSrv.DispatchLogicEvent(ClientEvent.OnUICDChange, cduiData);
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// private static AbilityTagContainer GetAbilityTagContainerFromSkillCfg(SkillDesc tbSkill)
|
|
// {
|
|
// var assetTagsLength = tbSkill.AssetTags.Length;
|
|
// var assetTags = new GameplayTag[assetTagsLength];
|
|
// for (var i = 0; i < assetTagsLength; i++)
|
|
// assetTags[i] = GetGameplayTag(tbSkill.AssetTags[i]);
|
|
//
|
|
// var cancelAbilityWithTagsLength = tbSkill.CancelAbilityWithTags.Length;
|
|
// var cancelAbilityWithTags = new GameplayTag[cancelAbilityWithTagsLength];
|
|
// for (var i = 0; i < cancelAbilityWithTagsLength; i++)
|
|
// cancelAbilityWithTags[i] = GetGameplayTag(tbSkill.CancelAbilityWithTags[i]);
|
|
//
|
|
// var blockAbilityWithTagsLength = tbSkill.BlockAbilityWithTags.Length;
|
|
// var blockAbilityWithTags = new GameplayTag[blockAbilityWithTagsLength];
|
|
// for (var i = 0; i < blockAbilityWithTagsLength; i++)
|
|
// blockAbilityWithTags[i] = GetGameplayTag(tbSkill.BlockAbilityWithTags[i]);
|
|
//
|
|
// var activationOwnedTagsLength = tbSkill.ActivationOwnedTags.Length;
|
|
// var activationOwnedTags = new GameplayTag[activationOwnedTagsLength];
|
|
// for (var i = 0; i < activationOwnedTagsLength; i++)
|
|
// activationOwnedTags[i] = GetGameplayTag(tbSkill.ActivationOwnedTags[i]);
|
|
//
|
|
// var activationRequiredTagsLength = tbSkill.ActivationRequiredTags.Length;
|
|
// var activationRequiredTags = new GameplayTag[activationRequiredTagsLength];
|
|
// for (var i = 0; i < activationRequiredTagsLength; i++)
|
|
// activationRequiredTags[i] = GetGameplayTag(tbSkill.ActivationRequiredTags[i]);
|
|
//
|
|
// var activationBlockedTagsLength = tbSkill.ActivationBlockedTags.Length;
|
|
// var activationBlockedTags = new GameplayTag[activationBlockedTagsLength];
|
|
// for (var i = 0; i < activationBlockedTagsLength; i++)
|
|
// activationBlockedTags[i] = GetGameplayTag(tbSkill.ActivationBlockedTags[i]);
|
|
//
|
|
// var tagContainer = new AbilityTagContainer(assetTags, cancelAbilityWithTags, blockAbilityWithTags,
|
|
// activationOwnedTags, activationRequiredTags, activationBlockedTags);
|
|
//
|
|
// return tagContainer;
|
|
// }
|
|
//
|
|
//
|
|
// public static GameplayTag GetGameplayTag(string tagName)
|
|
// {
|
|
// if (GTagLib.TagMap.TryGetValue(tagName, out var tag) != false) return tag;
|
|
// tag = new GameplayTag(tagName);
|
|
// GTagLib.TagMap.Add(tagName, tag);
|
|
// return tag;
|
|
// }
|
|
//
|
|
//
|
|
// public static GameplayEffect GetGameplayEffect(string effectPath)
|
|
// {
|
|
// if (string.IsNullOrEmpty(effectPath))
|
|
// return null;
|
|
//
|
|
//
|
|
// if (s_GameplayEffects.TryGetValue(effectPath, out var gea) == false)
|
|
// {
|
|
// var asset = SyncAssetLoader.GetAssetObject<GameplayEffectAsset>("GameplayEffectAsset", effectPath);
|
|
// if (asset == null)
|
|
// {
|
|
// XLog.LogWarning($"GetGameplayEffect: {effectPath} is null or not an GameplayEffectAsset");
|
|
// return null;
|
|
// }
|
|
//
|
|
// gea = new GameplayEffect(asset);
|
|
// s_GameplayEffects.Add(effectPath, gea);
|
|
// }
|
|
//
|
|
// return gea;
|
|
// }
|
|
// }
|
|
// }
|