103 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			103 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| --- @class BusyLevelItem
 | |
| local LevelItem = {}
 | |
| local Reactive = require("Core.Reactive")
 | |
| local RoleUtils = require("GamePlay.Utils.RoleUtils")
 | |
| local GameplayUtils = require("GamePlay.Utils")
 | |
| local KismetSystemLibrary = import("KismetSystemLibrary")
 | |
| 
 | |
| function LevelItem:ReceiveBeginPlay()
 | |
|     self:SetLevelItemID(self.CurrentItemID)
 | |
|     self.world = self:GetWorld()
 | |
|     print("LevelItem:ReceiveBeginPlay")
 | |
| end
 | |
| 
 | |
| 
 | |
| function LevelItem:TempSetting()
 | |
|     self:ReceiveBeginPlay()
 | |
| 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: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) |