更新
This commit is contained in:
parent
962aedcb0d
commit
f1728a045b
BIN
excel/level.xlsx
BIN
excel/level.xlsx
Binary file not shown.
@ -1,5 +1,5 @@
|
||||
[
|
||||
{"id":1,"type":1,"timeLimit":null,"atkBonus":1000,"hpBonus":1000,"wave":[[10,1,1,10,2,1],[10,1,1,10,2,1]]},
|
||||
{"id":1,"type":1,"timeLimit":null,"atkBonus":1000,"hpBonus":1000,"wave":[[10,1,1]]},
|
||||
{"id":2,"type":1,"timeLimit":null,"atkBonus":1000,"hpBonus":1000,"wave":[[10,1,1,10,2,1],[10,1,1,10,2,1],[10,1,1,10,2,1],[10,1,1,10,2,1]]},
|
||||
{"id":3,"type":1,"timeLimit":null,"atkBonus":1000,"hpBonus":1000,"wave":[[10,1,1,10,2,1],[10,1,1,10,2,1]]},
|
||||
{"id":4,"type":1,"timeLimit":null,"atkBonus":1000,"hpBonus":1000,"wave":[[10,1,1,10,2,1],[10,1,1,10,2,1],[10,1,1,10,2,1],[10,1,1,10,2,1]]},
|
||||
|
@ -9,8 +9,9 @@ local TypeList = require(script.Parent.TypeList)
|
||||
-- 刷新时,重新载入,暂时不考虑性能
|
||||
|
||||
-- 初始化内容
|
||||
function Behaviour:Init(Character: TypeList.Character)
|
||||
function Behaviour:Init(PlayerAI, Character: TypeList.Character)
|
||||
local self = {}
|
||||
self.PlayerAI = PlayerAI
|
||||
self.Character = Character
|
||||
self.CheckData = nil
|
||||
self.ExeTask = nil
|
||||
@ -44,18 +45,16 @@ function Behaviour:CheckStat()
|
||||
if self.Character:GetState("Died") then return false end
|
||||
|
||||
-- 执行状态中检查
|
||||
local FightingFolder = self.Character:FindFirstChild("Fighting")
|
||||
local ExecutingState = FightingFolder:FindFirstChild("ExecutingState")
|
||||
local ExecutingState = self.PlayerAI.ExecutingState
|
||||
-- 其他内容执行中,就false
|
||||
if ExecutingState.Value == true then return false end
|
||||
if ExecutingState == true then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
-- 改变当前执行状态标记
|
||||
function Behaviour:ChangeExecutingState(State: boolean)
|
||||
if not self.Character then warn("Behaviour Character not found") return end
|
||||
local FightingFolder = self.Character:FindFirstChild("Fighting")
|
||||
local ExecutingState = FightingFolder:FindFirstChild("ExecutingState")
|
||||
local ExecutingState = self.PlayerAI.ExecutingState
|
||||
ExecutingState.Value = State
|
||||
end
|
||||
|
||||
|
@ -5,7 +5,7 @@ Character.__index = Character
|
||||
local TypeList = require(script.Parent.TypeList)
|
||||
|
||||
local LIMIT_ATTRIBUTE = {
|
||||
"health"
|
||||
"hp"
|
||||
}
|
||||
|
||||
function Character.new(Player: Player, CharacterModel: Model, CharacterData: table): TypeList.Character
|
||||
@ -36,10 +36,12 @@ function Character.new(Player: Player, CharacterModel: Model, CharacterData: tab
|
||||
Attributes:SetAttribute("max" .. attributeKey, attributeValue)
|
||||
end
|
||||
end
|
||||
local conAttribute = Attributes.AttributeChanged:Connect(function(attributeKey: string, attributeValue: number)
|
||||
self:ChangeAttribute(attributeKey, attributeValue)
|
||||
end)
|
||||
table.insert(self.Connections, conAttribute)
|
||||
|
||||
-- 通过函数调用了,不绑定事件了
|
||||
-- local conAttribute = Attributes.AttributeChanged:Connect(function(attributeKey: string, attributeValue: number)
|
||||
-- self:ChangeAttributeValue(attributeKey, attributeValue)
|
||||
-- end)
|
||||
-- table.insert(self.Connections, conAttribute)
|
||||
|
||||
-- 配置角色状态数据
|
||||
local statsData = {
|
||||
@ -71,7 +73,9 @@ function Character:GetAttributeValue(attributeKey: string)
|
||||
return self.Config[attributeKey], self.Instance.Attributes:GetAttribute(attributeKey)
|
||||
end
|
||||
|
||||
function Character:ChangeAttribute(attributeKey: string, value: any)
|
||||
function Character:ChangeAttributeValue(attributeKey: string, value: any)
|
||||
if not attributeKey then warn("attributeKey is nil", attributeKey) return end
|
||||
if not value then warn("value is nil", value) return end
|
||||
local newValue = value
|
||||
-- 限制最大值
|
||||
if table.find(LIMIT_ATTRIBUTE, attributeKey) then
|
||||
@ -84,7 +88,7 @@ function Character:ChangeAttribute(attributeKey: string, value: any)
|
||||
self.Instance.Attributes:SetAttribute(attributeKey, newValue)
|
||||
|
||||
-- 死亡判断
|
||||
if attributeKey == "health" and self.Stats.Died == false then
|
||||
if attributeKey == "hp" and self.Stats.Died == false then
|
||||
if self.Config[attributeKey] <= 0 then
|
||||
self:Died()
|
||||
end
|
||||
|
@ -13,8 +13,8 @@ local MobsProxy = require(ServerStorage.Proxy.MobsProxy)
|
||||
local Move = {}
|
||||
Move.__index = Move
|
||||
|
||||
function Move:Init(Character: TypeList.Character, Player: Player)
|
||||
local self = Behaviour:Init(Character)
|
||||
function Move:Init(PlayerAI, Character: TypeList.Character, Player: Player)
|
||||
local self = Behaviour:Init(PlayerAI, Character)
|
||||
self.Player = Player
|
||||
setmetatable(self, Move)
|
||||
return self
|
||||
|
@ -56,7 +56,7 @@ function DamageProxy:TakeDamage(Caster: TypeList.Character, Victim: TypeList.Cha
|
||||
|
||||
-- 伤害计算
|
||||
local VictimHealth = Victim:GetAttributeValue("hp")
|
||||
Victim:ChangeAttribute("hp", math.max(0, VictimHealth - Damage))
|
||||
Victim:ChangeAttributeValue("hp", math.max(0, VictimHealth - Damage))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -91,9 +91,9 @@ task.defer(function()
|
||||
if not Player then return end
|
||||
if AI:GetModelDistance(MobInstance, Player.Character) <= 5 then
|
||||
-- 调用伤害模块
|
||||
DamageProxy:TakeDamage(MobInstance, Player.Character, {
|
||||
DamageProxy:TakeDamage(Mob, Mob.PlayerRole, {
|
||||
{
|
||||
Damage = 10,
|
||||
Damage = Mob.Config.attack,
|
||||
DamageType = DamageProxy.DamageType.PHYSICAL,
|
||||
DamageTag = DamageProxy.DamageTag.NORMAL
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ local Players = game:GetService("Players")
|
||||
|
||||
--> Variables
|
||||
local Utils = require(ReplicatedStorage.Tools.Utils)
|
||||
local PlayerInfoProxy = require(ServerStorage.Proxy.PlayerInfoProxy)
|
||||
local AI = require(script.AI)
|
||||
local Character = require(ServerStorage.Base.Character)
|
||||
local TypeList = require(ServerStorage.Base.TypeList)
|
||||
@ -39,7 +38,8 @@ end
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local Mob = {}
|
||||
Mob.__index = Character
|
||||
Mob.__index = Mob
|
||||
setmetatable(Mob, {__index = Character})
|
||||
|
||||
function Mob.new(Player: Player, MobId: number, OnMobDied: ((Player: Player, Mob: TypeList.Character) -> ())?)
|
||||
-- 获取玩家怪物目录
|
||||
@ -60,6 +60,8 @@ function Mob.new(Player: Player, MobId: number, OnMobDied: ((Player: Player, Mob
|
||||
-- 调用父类Character的new方法,初始化通用属性
|
||||
local self = Character.new(Player, newMobModel, MobData)
|
||||
setmetatable(self, Mob) -- 继承Mob方法
|
||||
local PlayerFightProxy = require(ServerStorage.Proxy.PlayerFightProxy)
|
||||
self.PlayerRole = PlayerFightProxy:GetPlayerRole(Player)
|
||||
|
||||
-- 放入关卡中
|
||||
newMobModel.Parent = playerMobsFolder
|
||||
@ -91,8 +93,8 @@ function MobsProxy:CreateMob(Player: Player, MobId: number, AtkBonus: number?, H
|
||||
local Mob = Mob.new(Player, MobId, OnMobDied)
|
||||
AI:StartTracking(Mob)
|
||||
-- 关卡系数
|
||||
if AtkBonus then Mob:ChangeAttribute("attack", math.floor(Mob.Config.attack * (AtkBonus / 1000))) end
|
||||
if HpBonus then Mob:ChangeAttribute("hp", math.floor(Mob.Config.hp * (HpBonus / 1000))) end
|
||||
-- if AtkBonus then Mob:ChangeAttributeValue("attack", math.floor(Mob.Config.attack * (AtkBonus / 1000))) end
|
||||
-- if HpBonus then Mob:ChangeAttributeValue("hp", math.floor(Mob.Config.hp * (HpBonus / 1000))) end
|
||||
MobsProxy.pData[Player.UserId][Mob.Instance] = Mob
|
||||
return Mob
|
||||
end
|
||||
|
@ -41,6 +41,7 @@ function PlayerAI.new(Player: Player, PlayerRole: TypeList.Character)
|
||||
setmetatable(self, PlayerAI)
|
||||
self.Character = PlayerRole
|
||||
self.Player = Player
|
||||
self.ExecutingState = false
|
||||
|
||||
self.BehaviourList = {}
|
||||
self.LoopTask = task.spawn(function()
|
||||
@ -75,7 +76,7 @@ end
|
||||
-- 动态添加行为
|
||||
function PlayerAI:AddBehaviour(BehaviourName: string)
|
||||
if not Behaviours[BehaviourName] then warn("Behaviour not found") return end
|
||||
local newBehaviour = Behaviours[BehaviourName]:Init(self.Character, self.Player)
|
||||
local newBehaviour = Behaviours[BehaviourName]:Init(self, self.Character, self.Player)
|
||||
self.BehaviourList[BehaviourName] = newBehaviour
|
||||
end
|
||||
|
||||
|
@ -30,12 +30,13 @@ end
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local PlayerRole = {}
|
||||
PlayerRole.__index = Character
|
||||
PlayerRole.__index = PlayerRole
|
||||
setmetatable(PlayerRole, {__index = Character})
|
||||
|
||||
function PlayerRole.new(Player: Player, CharacterId: number)
|
||||
local playerCharacter = WaitForCharacter(Player)
|
||||
|
||||
-- 获取怪物数据
|
||||
-- 获取玩家初始数据
|
||||
local CharacterData = Utils:GetIdDataFromJson(JsonCharacter, CharacterId)
|
||||
if not CharacterData then warn("CharacterId Data not found", CharacterId) return end
|
||||
|
||||
@ -52,7 +53,7 @@ end
|
||||
|
||||
function PlayerRole:Respawn()
|
||||
self:ChangeState("Died", false)
|
||||
self:ChangeAttribute("hp", self.Config.maxhp)
|
||||
self:ChangeAttributeValue("hp", self.Config.maxhp)
|
||||
-- 重置玩家位置
|
||||
|
||||
end
|
||||
@ -79,6 +80,13 @@ function PlayerFightProxy:InitPlayer(Player: Player)
|
||||
PlayerAI:AddBehaviour("Move")
|
||||
end
|
||||
|
||||
function PlayerFightProxy:GetPlayerRole(Player: Player)
|
||||
return PlayerFightProxy.pData[Player.UserId].PlayerRole
|
||||
end
|
||||
|
||||
function PlayerFightProxy:GetPlayerAI(Player: Player)
|
||||
return PlayerFightProxy.pData[Player.UserId].PlayerAI
|
||||
end
|
||||
|
||||
-- 重置玩家状态,但是不删除
|
||||
function PlayerFightProxy:CleanPlayer(Player: Player)
|
||||
|
Loading…
x
Reference in New Issue
Block a user