```
refactor(effectarg): 移动EffectArgs初始化逻辑 将EffectArgs的初始化从effectarg.go中的init函数移动到file.go的initfile函数中, 确保在使用前正确加载配置并初始化映射。 refactor(login): 更新Login方法中的Person调用 修改Login方法中对Person函数的调用,传递UserID参数以获取正确的用户信息。 refactor(user): 统一使用Person方法替代PersonOther 在UserSimInfo和UserMoreInfo方法中,将原先调用的PersonOther方法统一替换为 Person方法,保持代码一致性。 refactor(effect_damage): 简化属性获取和伤害计算逻辑 移除deepcopy相关逻辑,简化Effect0的OnSkill方法中的属性获取和伤害计算流程, 直接通过输入参数进行计算。 refactor(fightc): 优化玩家输入处理和战斗逻辑 更新GetInputByPlayer方法中的玩家判断逻辑,使用UserID比较代替对象比较; 在initplayer中添加InitAttackValue调用; 修复battleLoop中打印语句的格式问题; 调整技能攻击处理流程,增加SkillUseEnd回调调用。 refactor(attr): 改进属性获取方法和伤害计算逻辑 将GetProp方法重命名为Prop,并支持传入对方输入参数; 更新CalculatePower方法签名,使用Input类型代替BattlePetEntity; 在属性获取和伤害计算中正确处理双方属性影响。 refactor(playeraction): 简化技能使用逻辑 简化UseSkill方法中获取当前宠物信息的逻辑,去除冗余的条件判断; 在找到对应技能后添加break语句,提高执行效率。 refactor(reg): 更新Person方法实现 合并Person和PersonOther方法为统一的Person方法; 在数据库查询失败时添加错误处理,避免潜在的空指针异常。 ```
This commit is contained in:
@@ -11,11 +11,3 @@ type EffectArg struct {
|
||||
}
|
||||
|
||||
var EffectArgs map[int]int
|
||||
|
||||
func init() {
|
||||
EffectArgs = make(map[int]int)
|
||||
for _, t := range EffectArgsConfig.SideEffects.SideEffect {
|
||||
EffectArgs[t.ID] = t.SideEffectArgcount
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ func initfile() {
|
||||
MapConfig = getXml[Maps](path + "210.xml")
|
||||
ItemsConfig = getXml[Items](path + "43.xml")
|
||||
EffectArgsConfig = getJson[EffectArg](path + "side_effect.json")
|
||||
EffectArgs = make(map[int]int)
|
||||
for _, t := range EffectArgsConfig.SideEffects.SideEffect {
|
||||
EffectArgs[t.ID] = t.SideEffectArgcount
|
||||
|
||||
}
|
||||
ItemsMAP = utils.ToMap[Item, int](ItemsConfig.Items, func(m Item) int {
|
||||
return m.ID
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func (h *Controller) Login(data *user.MAIN_LOGIN_IN, c *player.Conn) (result *us
|
||||
|
||||
t := player.GetPlayer(c, data.Head.UserID)
|
||||
t.Service = blservice.NewUserService(data.Head.UserID)
|
||||
t.Info = t.Service.Person()
|
||||
t.Info = t.Service.Person(data.Head.UserID)
|
||||
t.Info.UserID = data.Head.UserID
|
||||
t.Onlinetime = uint32(time.Now().Unix()) //保存时间戳
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func (h Controller) UserSimInfo(data *user.SimUserInfoInboundInfo, c *player.Player) (result *user.SimUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
ret := &user.SimUserInfoOutboundInfo{}
|
||||
|
||||
copier.Copy(ret, c.Service.PersonOther(data.UserId))
|
||||
copier.Copy(ret, c.Service.Person(data.UserId))
|
||||
return ret, 0
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func (h Controller) UserSimInfo(data *user.SimUserInfoInboundInfo, c *player.Pla
|
||||
// 返回: 包含用户更多信息的输出结果和错误码。
|
||||
func (h Controller) UserMoreInfo(data *user.MoreUserInfoInboundInfo, c *player.Player) (result *user.MoreUserInfoOutboundInfo, err errorcode.ErrorCode) {
|
||||
ret := &user.MoreUserInfoOutboundInfo{}
|
||||
info := c.Service.PersonOther(data.UserId)
|
||||
info := c.Service.Person(data.UserId)
|
||||
copier.Copy(ret, info)
|
||||
|
||||
//todo 待实现
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"blazing/logic/service/fight/info"
|
||||
"blazing/logic/service/fight/input"
|
||||
"blazing/logic/service/fight/node"
|
||||
|
||||
"github.com/mohae/deepcopy"
|
||||
)
|
||||
|
||||
// 施加一个基类effect
|
||||
@@ -36,16 +34,7 @@ func (e *Effect0) TurnEnd(opp *input.Input) {
|
||||
// 使用技能时
|
||||
func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
|
||||
|
||||
e.Input.GetProp(func() { //还有视为属性
|
||||
oldour := deepcopy.Copy(e.Input.CurrentPet).(*info.BattlePetEntity)
|
||||
e.Input.Exec(func(t input.Effect) bool { //属性获取后
|
||||
|
||||
t.AfterAttr(opp.CurrentPet) //视为xx
|
||||
return true
|
||||
})
|
||||
e.Input.AttackValue.LostHp = uint32(e.Input.CalculatePower(opp.CurrentPet, skill).IntPart())
|
||||
e.Input.CurrentPet = oldour
|
||||
})
|
||||
e.Input.AttackValue.LostHp = uint32(e.Input.CalculatePower(opp, skill).IntPart())
|
||||
|
||||
e.Input.Exec(func(t input.Effect) bool { //计算暴击率加成
|
||||
|
||||
@@ -58,11 +47,11 @@ func (e *Effect0) OnSkill(opp *input.Input, skill *info.SkillEntity) {
|
||||
|
||||
}
|
||||
//这里注释掉,扣血在对方回合
|
||||
// if uint32(e.Input.AttackValue.LostHp) > opp.CurrentPet.Info.Hp {
|
||||
// opp.CurrentPet.Info.Hp = 0
|
||||
// } else {
|
||||
// opp.CurrentPet.Info.Hp = opp.CurrentPet.Info.Hp - e.Input.AttackValue.LostHp
|
||||
// }
|
||||
if uint32(e.Input.AttackValue.LostHp) > opp.CurrentPet.Info.Hp {
|
||||
opp.CurrentPet.Info.Hp = 0
|
||||
} else {
|
||||
opp.CurrentPet.Info.Hp = opp.CurrentPet.Info.Hp - e.Input.AttackValue.LostHp
|
||||
}
|
||||
|
||||
}
|
||||
func (this *Effect0) IsCrit(opp *input.Input, skill *info.SkillEntity) {
|
||||
|
||||
@@ -38,7 +38,7 @@ func (f *FightC) Ownerid() uint32 {
|
||||
}
|
||||
func (f *FightC) GetInputByPlayer(c common.PlayerI, isOpposite bool) *input.Input {
|
||||
// 判断当前玩家是否为我方玩家
|
||||
isOurPlayer := c == f.Our.Player
|
||||
isOurPlayer := c.GetInfo().UserID == f.ownerID
|
||||
|
||||
// 当isOurPlayer与isOpposite值不同时返回我方,相同时返回对方
|
||||
if isOurPlayer != isOpposite {
|
||||
@@ -79,7 +79,7 @@ func (f *FightC) initplayer(c common.PlayerI, opp bool) {
|
||||
|
||||
temp := input.NewInput(f, c)
|
||||
temp.AllPet = make([]*info.BattlePetEntity, 0)
|
||||
|
||||
temp.InitAttackValue()
|
||||
for i := 0; i < len(c.GetInfo().PetList); i++ {
|
||||
if f.Info.MAXPET == 0 || i < int(f.Info.MAXPET) {
|
||||
|
||||
@@ -271,7 +271,7 @@ func (f *FightC) battleLoop() {
|
||||
}
|
||||
|
||||
actions[uint32(action.GetPlayerID())] = action
|
||||
fmt.Println("玩家%i 执行动作", action.GetPlayerID())
|
||||
fmt.Println("玩家 执行动作", action.GetPlayerID(), action.Priority())
|
||||
|
||||
case <-timeout:
|
||||
|
||||
@@ -291,6 +291,7 @@ func (f *FightC) battleLoop() {
|
||||
p1Action := actions[f.Our.Player.GetInfo().UserID]
|
||||
p2Action := actions[f.Opp.Player.GetInfo().UserID]
|
||||
fmt.Println("开始结算回合")
|
||||
// 统一赋值,减少重复代码
|
||||
|
||||
var BattleActionI [2]BattleActionI
|
||||
BattleActionI[0], BattleActionI[1] = f.Compare(p1Action, p2Action)
|
||||
@@ -406,10 +407,6 @@ func (f *FightC) initAttackers(fattack BattleActionI) {
|
||||
|
||||
}
|
||||
|
||||
// 统一赋值,减少重复代码
|
||||
f.First.InitAttackValue()
|
||||
f.Second.InitAttackValue()
|
||||
|
||||
fmt.Println("先手", f.First.CurrentPet.Info.CatchTime, "后手", f.Second.CurrentPet.Info.CatchTime)
|
||||
|
||||
// TODO: 在这里调用技能结算逻辑
|
||||
@@ -437,12 +434,18 @@ func (f *FightC) processSkillAttack(attacker, defender *input.Input, a *SelectSk
|
||||
f.parseskill(attacker, defender, a) //命中后解析effect
|
||||
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
|
||||
|
||||
t.OnSkill(defender, a.Skill) //调用伤害计算
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
attacker.Exec(func(t input.Effect) bool {
|
||||
|
||||
t.SkillUseEnd(defender)
|
||||
|
||||
return true
|
||||
})
|
||||
// 扣减防御方血量
|
||||
} //todo 处理未命中效果
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func (i *Input) GetAction(opp *Input) {
|
||||
}
|
||||
|
||||
// todo获取属性,待实现获取后改回原属性
|
||||
func (i *Input) GetProp(f func()) {
|
||||
func (i *Input) Prop(in *Input, f func()) {
|
||||
oldour := deepcopy.Copy(i.CurrentPet).(*info.BattlePetEntity)
|
||||
//oldouo := deepcopy.Copy(opp.CurrentPet).(*info.BattlePetEntity)
|
||||
i.Exec(func(t Effect) bool { //属性获取前
|
||||
@@ -46,20 +46,21 @@ func (i *Input) GetProp(f func()) {
|
||||
return true
|
||||
})
|
||||
|
||||
// if in.UserID != i.UserID {
|
||||
// in.Exec(func(t input.Effect) bool { //属性获取后
|
||||
oldourr := deepcopy.Copy(in.CurrentPet).(*info.BattlePetEntity)
|
||||
in.Exec(func(t Effect) bool { //属性获取后
|
||||
|
||||
// t.AfterAttr(i.CurrentPet) //视为xx
|
||||
// return true
|
||||
// })
|
||||
// }
|
||||
t.AfterAttr(i.CurrentPet) //视为xx 需要在里面判断来源
|
||||
return true
|
||||
})
|
||||
f()
|
||||
in.CurrentPet = oldourr
|
||||
|
||||
i.CurrentPet = oldour //恢复
|
||||
//opp.CurrentPet = oldouo //恢复
|
||||
}
|
||||
|
||||
// 计算技能威力
|
||||
func (i *Input) CalculatePower(deftype *info.BattlePetEntity, skill *info.SkillEntity) decimal.Decimal {
|
||||
func (i *Input) CalculatePower(deftype *Input, skill *info.SkillEntity) decimal.Decimal {
|
||||
|
||||
//威力+区
|
||||
//威力*区
|
||||
@@ -73,16 +74,26 @@ func (i *Input) CalculatePower(deftype *info.BattlePetEntity, skill *info.SkillE
|
||||
defenseDec decimal.Decimal //防御值
|
||||
|
||||
)
|
||||
|
||||
switch skill.Category() { //判断技能类型
|
||||
case info.Category.PHYSICAL:
|
||||
i.Prop(i, func() { //我方取我方攻击
|
||||
attackDec = decimal.NewFromInt(int64(i.CurrentPet.Info.Prop[0]))
|
||||
})
|
||||
deftype.Prop(i, func() { //我方取敌方防御
|
||||
defenseDec = decimal.NewFromInt(int64(deftype.CurrentPet.Info.Prop[1]))
|
||||
|
||||
attackDec = decimal.NewFromInt(int64(i.CurrentPet.Info.Prop[0]))
|
||||
defenseDec = decimal.NewFromInt(int64(deftype.Info.Prop[1]))
|
||||
})
|
||||
|
||||
case info.Category.SPECIAL:
|
||||
|
||||
attackDec = decimal.NewFromInt(int64(i.CurrentPet.Info.Prop[2]))
|
||||
defenseDec = decimal.NewFromInt(int64(deftype.Info.Prop[3]))
|
||||
i.Prop(i, func() { //我方取我方攻击
|
||||
attackDec = decimal.NewFromInt(int64(i.CurrentPet.Info.Prop[2]))
|
||||
})
|
||||
deftype.Prop(i, func() { //我方取敌方防御
|
||||
defenseDec = decimal.NewFromInt(int64(deftype.CurrentPet.Info.Prop[3]))
|
||||
|
||||
})
|
||||
|
||||
default:
|
||||
return decimal.NewFromInt(0)
|
||||
@@ -96,9 +107,14 @@ func (i *Input) CalculatePower(deftype *info.BattlePetEntity, skill *info.SkillE
|
||||
Div(decimal.NewFromInt(50)).
|
||||
Add(decimal.NewFromInt(2))
|
||||
|
||||
t, _ := element.NewElementCalculator().GetOffensiveMultiplier(skill.Type().ID, deftype.Type().ID)
|
||||
var typeRate decimal.Decimal
|
||||
|
||||
typeRate := decimal.NewFromFloat(t)
|
||||
deftype.Prop(i, func() { //我方取敌方属性,得到敌方的实际和我方的视为
|
||||
t, _ := element.NewElementCalculator().GetOffensiveMultiplier(skill.Type().ID, deftype.CurrentPet.Type().ID)
|
||||
|
||||
typeRate = decimal.NewFromFloat(t)
|
||||
|
||||
})
|
||||
|
||||
damage := baseDamage.
|
||||
Mul(skill.CriticalsameTypeBonus()). // 同属性加成
|
||||
|
||||
@@ -57,16 +57,13 @@ func (f *FightC) UseSkill(c common.PlayerI, id int32) {
|
||||
ret := &SelectSkillAction{
|
||||
PlayerID: c.GetInfo().UserID,
|
||||
}
|
||||
if c.GetInfo().UserID == f.ownerID {
|
||||
ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
|
||||
} else {
|
||||
ret.PetInfo = f.GetInputByPlayer(c, true).CurrentPet
|
||||
}
|
||||
ret.PetInfo = f.GetInputByPlayer(c, false).CurrentPet
|
||||
|
||||
for _, v := range ret.PetInfo.Skills {
|
||||
|
||||
if v != nil && v.ID == int(id) {
|
||||
ret.Skill = v
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,16 +50,14 @@ func (s *UserService) Reg(nick string, color uint32) {
|
||||
//go s.InitTask()
|
||||
}
|
||||
|
||||
func (s *UserService) Person() (ret *model.PlayerInfo) {
|
||||
|
||||
return s.PersonOther(0)
|
||||
|
||||
}
|
||||
func (s *UserService) PersonOther(userid uint32) *model.PlayerInfo {
|
||||
func (s *UserService) Person(userid uint32) *model.PlayerInfo {
|
||||
|
||||
m := cool.DBM(s.info.Model).Where("player_id", userid)
|
||||
var tt model.PlayerEX
|
||||
m.Scan(&tt)
|
||||
err := m.Scan(&tt)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return tt.Data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user