初始化提交
This commit is contained in:
		
							
								
								
									
										27
									
								
								Content/Lua/GamePlay/Ability/Common/AbilityRoll.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Content/Lua/GamePlay/Ability/Common/AbilityRoll.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| local Ability = {} | ||||
| local GetGameplayTag = require("GamePlay.Utils").GetGameplayTag | ||||
| local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary") | ||||
|  | ||||
| function Ability:K2_ActivateAbilityFromEvent(_) | ||||
|     local RoleUtils = require("GamePlay.Utils.RoleUtils") | ||||
|  | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|     local asc = AbilitySystemBlueprintLibrary.GetAbilitySystemComponent(owner) | ||||
|  | ||||
|     local increase_handle = asc:MakeOutgoingSpec( | ||||
|         self.DefaultEffectConfig, 1, asc:MakeEffectContext() | ||||
|     ) | ||||
|     AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude( | ||||
|         increase_handle, GetGameplayTag("Change.Role.MoveSpeed"), self.SpeedIncrease | ||||
|     ) | ||||
|     asc:BP_ApplyGameplayEffectSpecToSelf(increase_handle) | ||||
|  | ||||
|     RoleUtils.ChangeHunger(owner, -100) | ||||
| end | ||||
|  | ||||
|  | ||||
| -- function Ability:K2_OnEndAbility(bWasCancelled) | ||||
| --     print(bWasCancelled, "Ability:K2_OnEndAbility") | ||||
| -- end | ||||
|  | ||||
| return Class(nil, nil, Ability) | ||||
							
								
								
									
										29
									
								
								Content/Lua/GamePlay/Ability/Common/EatFood.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								Content/Lua/GamePlay/Ability/Common/EatFood.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| local EatFoodAbility = {} | ||||
| local Utils = require("GamePlay.Utils") | ||||
| local RoleUtils = require("GamePlay.Utils.RoleUtils") | ||||
|  | ||||
| local function HandleHealthChange(role, effects) | ||||
|     local tag = Utils.GetGameplayTag("Change.Role.Health") | ||||
|     local value = effects:Get(tag) | ||||
|     if value ~= nil then | ||||
|         RoleUtils.ChangeHealth(role, value) | ||||
|     end | ||||
| end | ||||
|  | ||||
| local function HandleHungerChange(role, effects) | ||||
|     local tag = Utils.GetGameplayTag("Change.Role.Hunger") | ||||
|     local value = effects:Get(tag) | ||||
|     if value ~= nil then | ||||
|         RoleUtils.ChangeHunger(role, value) | ||||
|     end | ||||
| end | ||||
|  | ||||
| function EatFoodAbility:K2_ActivateAbilityFromEvent(EventData) | ||||
|     local item_config = Utils.GetItemConfigByID(math.floor(EventData.EventMagnitude)) | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|     HandleHealthChange(owner, item_config.GameplayEffects) | ||||
|     HandleHungerChange(owner, item_config.GameplayEffects) | ||||
|     self:K2_EndAbility() | ||||
| end | ||||
|  | ||||
| return Class(nil, nil, EatFoodAbility) | ||||
							
								
								
									
										94
									
								
								Content/Lua/GamePlay/Ability/Common/Pick.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								Content/Lua/GamePlay/Ability/Common/Pick.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,94 @@ | ||||
| local Ability = {} | ||||
| local EBusyRoleState = import("EBusyRoleState") | ||||
| local ERoleMoveDirection = import("ERoleMoveDirection") | ||||
| local EBusyAnimationPhase = import("EBusyAnimationPhase") | ||||
| local KismetSystemLibrary = import("KismetSystemLibrary") | ||||
| local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary") | ||||
| local GetGameplayTag = require("GamePlay.Utils").GetGameplayTag | ||||
|  | ||||
| local item_pick_tag = "Change.LevelItem.Health" | ||||
| local role_pick_cost_health_tag = "Change.Role.Health" | ||||
| local role_pick_cost_hunger_tag = "Change.Role.Hunger" | ||||
|  | ||||
|  | ||||
| local function GetSelfPickConsume(item_id) | ||||
|  | ||||
|  | ||||
| end | ||||
|  | ||||
|  | ||||
| function Ability:ctor() | ||||
|     self.target = nil | ||||
|     self.pick_phase = nil | ||||
|     self.delay_timer = nil | ||||
|     self.event_data = nil | ||||
| end | ||||
|  | ||||
| function Ability:K2_ActivateAbilityFromEvent(EventData) | ||||
|     print("Pick  Ability:K2_ActivateAbility") | ||||
|     self.pick_phase = EBusyAnimationPhase.PrepareCast | ||||
|  | ||||
|     self:ProcessAbilityPhase() | ||||
|     self.event_data = EventData | ||||
|     self.target = EventData.Target | ||||
| end | ||||
|  | ||||
| function Ability:K2_OnEndAbility() | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|     if self.target:IsAlive() then | ||||
|         owner:TryActiveAbility("Ability.Role.Pick", self.event_data) | ||||
|     else | ||||
|         owner.proxy.state = EBusyRoleState.PickFinished | ||||
|         owner:UpdateRoleState() | ||||
|     end | ||||
| end | ||||
|  | ||||
| function Ability:ProcessAbilityPhase() | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|     local Animation = owner["RoleAnimation"] | ||||
|  | ||||
|     Animation:PlayPickAnimation("Tree", Animation:GetMoveDirection(), self.pick_phase, 1.0) | ||||
|     if self.delay_timer ~= nil then | ||||
|         KismetSystemLibrary.K2_ClearTimerHandle(self, self.delay_timer) | ||||
|     end | ||||
|  | ||||
|     if self.pick_phase == EBusyAnimationPhase.PrepareCast then | ||||
|         local delegate = slua.createDelegate(function() | ||||
|             self.pick_phase = EBusyAnimationPhase.Casting | ||||
|             self:ProcessAbilityPhase() | ||||
|         end) | ||||
|         self.delay_timer = KismetSystemLibrary.K2_SetTimerDelegate(delegate, 0.5, false, true, 0, 0) | ||||
|     elseif self.pick_phase == EBusyAnimationPhase.Casting then | ||||
|         self.pick_phase = EBusyAnimationPhase.PostCast | ||||
|         self:ProcessAbilityPhase() | ||||
|         self:ApplayEffect(owner.RoleAbility) | ||||
|     else | ||||
|         local delegate = slua.createDelegate(function() | ||||
|             self:K2_EndAbility() | ||||
|         end) | ||||
|         self.delay_timer = KismetSystemLibrary.K2_SetTimerDelegate(delegate, 0.2, false, true, 0, 0) | ||||
|     end | ||||
| end | ||||
|  | ||||
| function Ability:ApplayEffect(asc) | ||||
|     local RoleUtils = require("GamePlay.Utils.RoleUtils") | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|  | ||||
|     -- 物品的采集效果 | ||||
|     local item_asc = AbilitySystemBlueprintLibrary.GetAbilitySystemComponent(self.target) | ||||
|     local pick_handle = asc:MakeOutgoingSpec( | ||||
|         self.AbilityEffectConfigs:Get("LevelItem"), 1, asc:MakeEffectContext() | ||||
|     ) | ||||
|     AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude( | ||||
|         pick_handle, GetGameplayTag(item_pick_tag), -owner.RoleConfig.PickEffect | ||||
|     ) | ||||
|  | ||||
|     -- 自己的消耗 | ||||
|     RoleUtils.ChangeHunger(owner,-self.target.LevelItemConfig.PickHungerCost) | ||||
|  | ||||
|     asc:BP_ApplyGameplayEffectSpecToTarget(pick_handle, item_asc) | ||||
| end | ||||
|  | ||||
|  | ||||
|  | ||||
| return Class(nil, nil, Ability) | ||||
							
								
								
									
										26
									
								
								Content/Lua/GamePlay/Ability/Common/Recover.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								Content/Lua/GamePlay/Ability/Common/Recover.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| local Ability = {} | ||||
| local GetGameplayTag = require("GamePlay.Utils").GetGameplayTag | ||||
| local BlueprintGameplayTagLibrary = import("BlueprintGameplayTagLibrary") | ||||
| local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary") | ||||
|  | ||||
| function Ability:K2_ActivateAbilityFromEvent(EventData) | ||||
|  | ||||
|     local tag = EventData.tag | ||||
|     local value = EventData.EventMagnitude | ||||
|     local asc = AbilitySystemBlueprintLibrary.GetAbilitySystemComponent(self.target) | ||||
|  | ||||
|     if tag == "Recover.Role.Health" then | ||||
|         local spec_handle = asc:MakeOutgoingSpec( | ||||
|             self.AbilityEffectConfigs:Get("Role"), 1, asc:MakeEffectContext() | ||||
|         ) | ||||
|         AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude( | ||||
|             spec_handle, GetGameplayTag("Change.Role.Health"), value | ||||
|         ) | ||||
|         asc:BP_ApplyGameplayEffectSpecToSelf(spec_handle) | ||||
|     end | ||||
|  | ||||
| end | ||||
|  | ||||
|  | ||||
|  | ||||
| return Class(nil, nil, Ability) | ||||
							
								
								
									
										71
									
								
								Content/Lua/GamePlay/Ability/Common/RoleConsume.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Content/Lua/GamePlay/Ability/Common/RoleConsume.lua
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,71 @@ | ||||
| local Ability = {} | ||||
| local Reactive = require("Core.Reactive") | ||||
| local GetGameplayTag = require("GamePlay.Utils").GetGameplayTag | ||||
| local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary") | ||||
|  | ||||
| local hunger_consume_tag_name = "Buff.RoleConsume.Hunger" | ||||
| local health_consume_tag_name = "Buff.RoleConsume.Health" | ||||
|  | ||||
| function Ability:K2_ActivateAbilityFromEvent(_) | ||||
|     print("Role Consume Ability:K2_ActivateAbility") | ||||
|     if self.hunger_watcher ~= nil then | ||||
|         self.hunger_watcher:Destroy() | ||||
|     end | ||||
|     self.hunger_watcher = Reactive.Watcher(function() self:ConsumeWatcher() end) | ||||
| end | ||||
|  | ||||
| function Ability:ConsumeWatcher() | ||||
|     local owner = self:GetOwningActorFromActorInfo() | ||||
|     local asc = owner["RoleAbility"] | ||||
|     if owner.LuaRoleAttribute.Hunger > 0 then | ||||
|         if not asc:IsGameplayCueActive(GetGameplayTag(hunger_consume_tag_name)) then | ||||
|             self:ApplyHungerConsume(asc) | ||||
|         end | ||||
|         if asc:IsGameplayCueActive(GetGameplayTag(health_consume_tag_name)) then | ||||
|             if self.health_consume_handle ~= nil then | ||||
|                 asc:RemoveActiveGameplayEffect(self.health_consume_handle, -1) | ||||
|             end | ||||
|             self.health_consume_handle = nil | ||||
|         end | ||||
|     elseif owner.LuaRoleAttribute.Hunger <= 0 then | ||||
|         if not asc:IsGameplayCueActive(GetGameplayTag(health_consume_tag_name)) then | ||||
|             self:ApplyHealthConsume(asc) | ||||
|         end | ||||
|         if asc:IsGameplayCueActive(GetGameplayTag(hunger_consume_tag_name)) then | ||||
|             if self.hunger_consume_handle ~= nil then | ||||
|                 asc:RemoveActiveGameplayEffect(self.hunger_consume_handle, -1) | ||||
|             end | ||||
|             self.hunger_consume_handle = nil | ||||
|             owner.LuaRoleAttribute.Hunger = 0 | ||||
|         end | ||||
|     end | ||||
| end | ||||
|  | ||||
| function Ability:ApplyConsumeEffect(asc, effect_tag_name, value) | ||||
|     local spec_handle = asc:MakeOutgoingSpec( | ||||
|         self.EffectConfigs:Get(GetGameplayTag(effect_tag_name)), | ||||
|         1, asc:MakeEffectContext() | ||||
|     ) | ||||
|     AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude( | ||||
|         spec_handle, GetGameplayTag(effect_tag_name), value | ||||
|     ) | ||||
|     return asc:BP_ApplyGameplayEffectSpecToSelf(spec_handle) | ||||
| end | ||||
|  | ||||
| function Ability:ApplyHungerConsume(asc) | ||||
|     local owner = asc:GetOwner() | ||||
|     local consume_speed_peer_second = owner.RoleConfig.HungerConsumeSpeed | ||||
|     self.hunger_consume_handle = self:ApplyConsumeEffect( | ||||
|         asc, hunger_consume_tag_name, -consume_speed_peer_second / 10 | ||||
|     ) | ||||
| end | ||||
|  | ||||
| function Ability:ApplyHealthConsume(asc) | ||||
|     local owner = asc:GetOwner() | ||||
|     local consume_speed_peer_second = owner.RoleConfig.HungerConsumeSpeed | ||||
|     self.health_consume_handle = self:ApplyConsumeEffect( | ||||
|         asc, health_consume_tag_name, -consume_speed_peer_second/10 | ||||
|     ) | ||||
| end | ||||
|  | ||||
| return Class(nil, nil,  Ability) | ||||
		Reference in New Issue
	
	Block a user