2025-06-05 17:47:59 +08:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
2025-06-06 18:31:44 +08:00
|
|
|
"ecs/proto"
|
2025-06-05 17:47:59 +08:00
|
|
|
"ecs/proto/pb"
|
|
|
|
"ecs/servers/game/data"
|
2025-06-09 18:33:52 +08:00
|
|
|
"github.com/oylshe1314/framework/util"
|
2025-06-05 17:47:59 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (this *Player) EnterBattle(sceneTable *data.Scene) {
|
|
|
|
this.Temp.Fighting = true
|
2025-06-09 18:33:52 +08:00
|
|
|
this.Temp.RandSeed = util.DefaultRandom.Uint64()
|
2025-06-05 17:47:59 +08:00
|
|
|
|
|
|
|
this.enterScene(uint32(sceneTable.Id))
|
2025-06-16 18:49:53 +08:00
|
|
|
this.copyBattle(sceneTable)
|
2025-06-05 17:47:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) EndBattle() {
|
|
|
|
this.Temp.Fighting = false
|
|
|
|
this.Temp.RandSeed = 0
|
2025-06-13 17:19:56 +08:00
|
|
|
this.enterScene(0)
|
2025-06-05 17:47:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) copyBattle(sceneTable *data.Scene) {
|
|
|
|
var ack, err = this.virtualBattle(sceneTable)
|
|
|
|
if err != nil {
|
|
|
|
_ = this.TipNotice(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-06-13 17:19:56 +08:00
|
|
|
if ack.Succeed {
|
2025-06-05 17:47:59 +08:00
|
|
|
this.PassedCopy(sceneTable, ack.Score)
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = this.Send(uint16(pb.ModId_ModuleBattle), uint16(pb.MsgId_ModBattleEnter), ack)
|
|
|
|
}
|
|
|
|
|
2025-06-16 18:49:53 +08:00
|
|
|
type _BattleBuff struct {
|
|
|
|
id uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type _BattleSkill struct {
|
|
|
|
id uint32
|
|
|
|
buffs []*_BattleBuff
|
|
|
|
}
|
|
|
|
|
|
|
|
type _BattleUnit struct {
|
|
|
|
id uint64
|
|
|
|
attrs Attrs
|
|
|
|
attackSkills []*_BattleSkill
|
|
|
|
passiveSkills []*_BattleSkill
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) virtualBattle(sceneTable *data.Scene) (ack *pb.BattleEnterAck, tip proto.TipError) {
|
|
|
|
var lineup = util.MapFindValue(this.Lineup, func(lineup *PlayerLineup) bool {
|
|
|
|
return lineup.Active
|
|
|
|
})
|
|
|
|
if lineup == nil {
|
|
|
|
return nil, proto.TipLineupNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
var heroes = make([]*_BattleUnit, 6)
|
|
|
|
for i := range 6 {
|
|
|
|
if lineup.Heroes[i] != nil {
|
|
|
|
if hero := this.Hero[lineup.Heroes[i].HeroUid]; hero != nil {
|
|
|
|
heroes[lineup.Heroes[i].Position-1] = &_BattleUnit{
|
|
|
|
id: lineup.Heroes[i].HeroUid,
|
|
|
|
attrs: hero.Attrs(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var enemies []*_BattleUnit
|
|
|
|
if pb.CopyType(sceneTable.CopyType) == pb.CopyType_CopyArena {
|
|
|
|
|
|
|
|
} else {
|
|
|
|
enemies, tip = this.loadMonsters([]int{sceneTable.Monster1, sceneTable.Monster2, sceneTable.Monster3, sceneTable.Monster4, sceneTable.Monster5, sceneTable.Monster6})
|
|
|
|
if tip != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ack = &pb.BattleEnterAck{
|
|
|
|
SceneId: uint32(sceneTable.Id),
|
|
|
|
RewardList: nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
ack.Heroes = make([]*pb.BattleUnit, 6)
|
|
|
|
ack.Enemies = make([]*pb.BattleUnit, 6)
|
|
|
|
for i := range 6 {
|
|
|
|
if heroes[i] != nil {
|
|
|
|
ack.Heroes[i] = &pb.BattleUnit{UnitId: heroes[i].id}
|
|
|
|
}
|
|
|
|
if enemies[i] != nil {
|
|
|
|
ack.Enemies[i] = &pb.BattleUnit{UnitId: enemies[i].id}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ack.Succeed, ack.Score, ack.RoundList = this.calcBattle(heroes, enemies)
|
|
|
|
ack.BattleRounds = uint32(len(ack.RoundList))
|
|
|
|
|
|
|
|
return ack, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) calcBattle(heroes, enemies []*_BattleUnit) (bool, int32, []*pb.BattleRound) {
|
|
|
|
return true, 3, []*pb.BattleRound{
|
|
|
|
{
|
|
|
|
BattleRound: 1,
|
|
|
|
ActionList: []*pb.BattleAction{
|
|
|
|
{
|
|
|
|
Caster: &pb.BattleTarget{
|
|
|
|
Type: 1,
|
|
|
|
Id: heroes[0].id,
|
|
|
|
HpMax: heroes[0].attrs[pb.AttrType_Hp],
|
|
|
|
Rage: 0,
|
|
|
|
Status: nil,
|
|
|
|
Value: nil,
|
|
|
|
Hp: nil,
|
|
|
|
},
|
|
|
|
Type: 0,
|
|
|
|
SkillId: 100021,
|
|
|
|
TargetList: []*pb.BattleTarget{
|
|
|
|
{
|
|
|
|
Type: 2,
|
|
|
|
Id: enemies[0].id,
|
|
|
|
HpMax: enemies[0].attrs[pb.AttrType_Hp],
|
|
|
|
Rage: 0,
|
|
|
|
Status: nil,
|
|
|
|
Value: []uint64{heroes[0].attrs[pb.AttrType_Attack]},
|
|
|
|
Hp: []uint64{enemies[0].attrs[pb.AttrType_Hp] - heroes[0].attrs[pb.AttrType_Attack]},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Caster: &pb.BattleTarget{
|
|
|
|
Type: 2,
|
|
|
|
Id: enemies[1].id,
|
|
|
|
HpMax: enemies[1].attrs[pb.AttrType_Hp],
|
|
|
|
Rage: 0,
|
|
|
|
Status: nil,
|
|
|
|
Value: nil,
|
|
|
|
Hp: nil,
|
|
|
|
},
|
|
|
|
Type: 0,
|
|
|
|
SkillId: 100191,
|
|
|
|
TargetList: []*pb.BattleTarget{
|
|
|
|
{
|
|
|
|
Type: 1,
|
|
|
|
Id: heroes[0].id,
|
|
|
|
HpMax: heroes[0].attrs[pb.AttrType_Hp],
|
|
|
|
Rage: 0,
|
|
|
|
Status: nil,
|
|
|
|
Value: []uint64{enemies[1].attrs[pb.AttrType_Attack]},
|
|
|
|
Hp: []uint64{heroes[0].attrs[pb.AttrType_Hp] - enemies[1].attrs[pb.AttrType_Attack]},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) loadMonsters(monsterIds []int) (unitList []*_BattleUnit, tip proto.TipError) {
|
|
|
|
unitList = make([]*_BattleUnit, len(monsterIds))
|
|
|
|
for i, monsterId := range monsterIds {
|
|
|
|
if monsterId == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var monsterTable = this.manager.tables.Monster.Find(int(monsterId))
|
|
|
|
if monsterTable == nil {
|
|
|
|
return nil, proto.TipDataTablesError
|
|
|
|
}
|
|
|
|
|
|
|
|
var unit = &_BattleUnit{id: uint64(monsterTable.Id)}
|
|
|
|
|
|
|
|
unit.attackSkills, tip = this.loadSkills(monsterTable.AttackSkills)
|
|
|
|
if tip != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
unit.passiveSkills, tip = this.loadSkills(monsterTable.PassiveSkills)
|
|
|
|
if tip != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
unit.attrs[pb.AttrType_Attack] = uint64(monsterTable.AttrValue1)
|
|
|
|
unit.attrs[pb.AttrType_Hp] = uint64(monsterTable.AttrValue2)
|
|
|
|
unit.attrs[pb.AttrType_AttrPhysicalDefense] = uint64(monsterTable.AttrValue3)
|
|
|
|
unit.attrs[pb.AttrType_AttrMagicDefense] = uint64(monsterTable.AttrValue4)
|
|
|
|
unit.attrs[pb.AttrType_AttrAttackRatio] = uint64(monsterTable.AttrValue5)
|
|
|
|
unit.attrs[pb.AttrType_AttrHpRatio] = uint64(monsterTable.AttrValue6)
|
|
|
|
unit.attrs[pb.AttrType_AttrPhysicalDefenseRatio] = uint64(monsterTable.AttrValue7)
|
|
|
|
unit.attrs[pb.AttrType_AttrMagicDefenseRatio] = uint64(monsterTable.AttrValue8)
|
|
|
|
unit.attrs[pb.AttrType_AttrDamageRatio] = uint64(monsterTable.AttrValue9)
|
|
|
|
unit.attrs[pb.AttrType_AttrDamageRelief] = uint64(monsterTable.AttrValue10)
|
|
|
|
unit.attrs[pb.AttrType_AttrCriticalRatio] = uint64(monsterTable.AttrValue11)
|
|
|
|
unit.attrs[pb.AttrType_AttrCriticalResistance] = uint64(monsterTable.AttrValue12)
|
|
|
|
unit.attrs[pb.AttrType_AttrCriticalDamage] = uint64(monsterTable.AttrValue13)
|
|
|
|
unit.attrs[pb.AttrType_AttrCriticalDamageRelief] = uint64(monsterTable.AttrValue14)
|
|
|
|
unit.attrs[pb.AttrType_AttrHitRate] = uint64(monsterTable.AttrValue15)
|
|
|
|
unit.attrs[pb.AttrType_AttrDodgeRate] = uint64(monsterTable.AttrValue16)
|
|
|
|
unit.attrs[pb.AttrType_AttrTreatRatio] = uint64(monsterTable.AttrValue17)
|
|
|
|
unit.attrs[pb.AttrType_AttrByTreatedRatio] = uint64(monsterTable.AttrValue18)
|
|
|
|
unit.attrs[pb.AttrType_AttrFinalDamageRatio] = uint64(monsterTable.AttrValue19)
|
|
|
|
unit.attrs[pb.AttrType_AttrFinalDamageRelief] = uint64(monsterTable.AttrValue20)
|
|
|
|
|
|
|
|
unitList[i] = unit
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) loadSkills(skillIds []int) (skillList []*_BattleSkill, tip proto.TipError) {
|
|
|
|
skillList = make([]*_BattleSkill, len(skillIds))
|
|
|
|
for _, skillId := range skillIds {
|
|
|
|
var skillTable = this.manager.tables.Skill.Find(skillId)
|
|
|
|
if skillTable == nil {
|
|
|
|
return nil, proto.TipDataTablesError
|
|
|
|
}
|
|
|
|
|
|
|
|
var skill = &_BattleSkill{
|
|
|
|
id: uint32(skillId),
|
|
|
|
}
|
|
|
|
|
|
|
|
skill.buffs, tip = this.loadSkillsBuff(skillTable.SkillBuff)
|
|
|
|
if tip != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Player) loadSkillsBuff(buffIds []int) (buffList []*_BattleBuff, tip proto.TipError) {
|
|
|
|
buffList = make([]*_BattleBuff, len(buffIds))
|
|
|
|
for i, skillId := range buffIds {
|
|
|
|
var buff = this.manager.tables.SkillBuff.Find(skillId)
|
|
|
|
if buff == nil {
|
|
|
|
return nil, proto.TipDataTablesError
|
|
|
|
}
|
|
|
|
|
|
|
|
var battleBuff = &_BattleBuff{
|
|
|
|
id: uint32(skillId),
|
|
|
|
}
|
|
|
|
|
|
|
|
buffList[i] = battleBuff
|
|
|
|
}
|
|
|
|
return buffList, nil
|
2025-06-05 17:47:59 +08:00
|
|
|
}
|