diff --git a/common/data/xmlres/effectarg.go b/common/data/xmlres/effectarg.go index 1d56171e0..3c40e9d2d 100644 --- a/common/data/xmlres/effectarg.go +++ b/common/data/xmlres/effectarg.go @@ -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 - - } -} diff --git a/common/data/xmlres/file.go b/common/data/xmlres/file.go index 4ecd63219..a77836888 100644 --- a/common/data/xmlres/file.go +++ b/common/data/xmlres/file.go @@ -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 diff --git a/logic/controller/login.go b/logic/controller/login.go index f5d413794..f7a0f4653 100644 --- a/logic/controller/login.go +++ b/logic/controller/login.go @@ -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()) //保存时间戳 diff --git a/logic/controller/user.go b/logic/controller/user.go index 423437909..2a3d988a9 100644 --- a/logic/controller/user.go +++ b/logic/controller/user.go @@ -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 待实现 diff --git a/logic/service/fight/effect/effect_damage.go b/logic/service/fight/effect/effect_damage.go index ca144cc76..65b0a8e5b 100644 --- a/logic/service/fight/effect/effect_damage.go +++ b/logic/service/fight/effect/effect_damage.go @@ -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) { diff --git a/logic/service/fight/fightc.go b/logic/service/fight/fightc.go index a2fdc5e34..c0b350f18 100644 --- a/logic/service/fight/fightc.go +++ b/logic/service/fight/fightc.go @@ -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 处理未命中效果 diff --git a/logic/service/fight/input/attr.go b/logic/service/fight/input/attr.go index 07052d6a0..813fec144 100644 --- a/logic/service/fight/input/attr.go +++ b/logic/service/fight/input/attr.go @@ -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()). // 同属性加成 diff --git a/logic/service/fight/playeraction.go b/logic/service/fight/playeraction.go index afaf16b57..16b508d89 100644 --- a/logic/service/fight/playeraction.go +++ b/logic/service/fight/playeraction.go @@ -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 } } diff --git a/modules/blazing/service/reg.go b/modules/blazing/service/reg.go index 7971977b7..5574ed2a3 100644 --- a/modules/blazing/service/reg.go +++ b/modules/blazing/service/reg.go @@ -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