94 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
		
		
			
		
	
	
			94 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
|  | 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) |