初始化提交
This commit is contained in:
125
Content/Lua/GamePlay/LevelItem/LevelItem.lua
Normal file
125
Content/Lua/GamePlay/LevelItem/LevelItem.lua
Normal file
@ -0,0 +1,125 @@
|
||||
--- @class BusyLevelItem
|
||||
local LevelItem = {}
|
||||
local Reactive = require("Core.Reactive")
|
||||
local RoleUtils = require("GamePlay.Utils.RoleUtils")
|
||||
local GameplayUtils = require("GamePlay.Utils")
|
||||
local KismetSystemLibrary = import("KismetSystemLibrary")
|
||||
|
||||
--[[
|
||||
|
||||
Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_0" ExportPath="/Script/BlueprintGraph.K2Node_CallFunction'/Game/Blueprint/Bp_BusyCharacter.Bp_BusyCharacter:EventGraph.K2Node_CallFunction_0'"
|
||||
bIsPureFunc=True
|
||||
FunctionReference=(MemberParent="/Script/CoreUObject.Class'/Script/Engine.KismetSystemLibrary'",MemberName="IsValid")
|
||||
NodePosX=416
|
||||
NodePosY=576
|
||||
NodeGuid=FAEC35AE4921EA704624228C12C6567F
|
||||
CustomProperties Pin (PinId=560B26AF426C21B8AC88EDB90990EDF1,PinName="self",PinFriendlyName=NSLOCTEXT("K2Node", "Target", "Target"),PinToolTip="Target\nKismet System Library Object Reference",PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject="/Script/CoreUObject.Class'/Script/Engine.KismetSystemLibrary'",PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultObject="/Script/Engine.Default__KismetSystemLibrary",PersistentGuid=00000000000000000000000000000000,bHidden=True,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=5F3C3BC8429FA25D9B78099F2107C098,PinName="Object",PinToolTip="Object\nObject Reference",PinType.PinCategory="object",PinType.PinSubCategory="",PinType.PinSubCategoryObject="/Script/CoreUObject.Class'/Script/CoreUObject.Object'",PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=True,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
CustomProperties Pin (PinId=5C7188354FCB6B61DE0AC8A14D6E3EEC,PinName="ReturnValue",PinToolTip="Return Value\nBoolean\n\nReturn true if the object is usable : non-null and not pending kill",Direction="EGPD_Output",PinType.PinCategory="bool",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,DefaultValue="false",AutogeneratedDefaultValue="false",PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,)
|
||||
End Object
|
||||
|
||||
|
||||
]]
|
||||
|
||||
function LevelItem:ReceiveBeginPlay()
|
||||
self.Super:ReceiveBeginPlay()
|
||||
self:SetLevelItemID(self.CurrentItemID)
|
||||
self.world = self:GetWorld()
|
||||
end
|
||||
|
||||
function LevelItem:ReceiveLevelItemSetted(Config)
|
||||
self.config = Config
|
||||
self.PickBar.Widget:BindLevelItem(self)
|
||||
|
||||
print("LevelItem:ReceiveLevelItemSetted", KismetSystemLibrary.IsValid(self))
|
||||
|
||||
|
||||
self.attribute_watcher = Reactive.Watcher(function()
|
||||
if self.LuaLevelItemAttribute.Health <= 0 then
|
||||
self:GenerateDropItems()
|
||||
local location = self:K2_GetActorLocation()
|
||||
location.Z = -1000
|
||||
self:K2_SetActorLocation(location, false, nil, false)
|
||||
self:SetLifeSpan(0.3)
|
||||
self.attribute_watcher:Destroy()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- function LevelItem:ReceiveDamage(value)
|
||||
-- local remain = self.proxy.RemainProcess - value
|
||||
-- if remain > 0 then
|
||||
-- self.proxy.RemainProcess = remain
|
||||
-- return true
|
||||
-- else
|
||||
-- self.proxy.RemainProcess = 0
|
||||
-- self:SetLifeSpan(0.3)
|
||||
-- return false
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function LevelItem:GenerateDropItems()
|
||||
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem").Get(self.world)
|
||||
local role = RoleUtils.GetRole(self)
|
||||
local role_location = role:K2_GetActorLocation()
|
||||
local curr_location = self:K2_GetActorLocation()
|
||||
|
||||
local collection_config = GameplayUtils.GetItemConfigByID(self.CurrentItemID)
|
||||
|
||||
local generated_dict = {}
|
||||
for _, config in pairs(collection_config.DropConfigs) do
|
||||
local base = 0
|
||||
local seed = math.random()
|
||||
for _, rate in pairs(config.configs) do
|
||||
local min = base
|
||||
local max = base + rate.Rate
|
||||
if seed >= min and seed < max then
|
||||
generated_dict[config.ItemID] = rate.Count
|
||||
break
|
||||
end
|
||||
base = max
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
for item_id, count in pairs(generated_dict) do
|
||||
for _ = 1, count do
|
||||
local reward = BusyActorManagerSubSystem:SpawnLevelItemReward(self)
|
||||
|
||||
reward.Movement.speed = 300.0
|
||||
reward.Movement.accelerate = 600.0
|
||||
reward.Movement.direction = {
|
||||
X = curr_location.X - role_location.X,
|
||||
Y = curr_location.Y - role_location.Y
|
||||
}
|
||||
reward:SetRewardID(item_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
-- 接口
|
||||
function LevelItem:GetPickProcess()
|
||||
local process = self.LuaLevelItemAttribute.Health / self.config.PickTimeCost
|
||||
print("current process", process)
|
||||
return process
|
||||
end
|
||||
|
||||
|
||||
function LevelItem:GetPickCost()
|
||||
return self.LevelItemConfig.PickHungerCost
|
||||
end
|
||||
|
||||
function LevelItem:IsAlive()
|
||||
return self.LuaLevelItemAttribute.Health > 0
|
||||
end
|
||||
|
||||
function LevelItem:GetItemID()
|
||||
return self.CurrentItemID
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, LevelItem)
|
||||
Reference in New Issue
Block a user