diff --git a/logic/controller/map.go b/logic/controller/map.go index b3cf61844..6fa94b2fd 100644 --- a/logic/controller/map.go +++ b/logic/controller/map.go @@ -3,12 +3,10 @@ package controller import ( "blazing/common/data/entity" "blazing/common/socket/errorcode" - "blazing/common/socket/handler" "blazing/logic/service/maphot" "blazing/logic/service/maps" "blazing/logic/service/space" mservice "blazing/modules/blazing/service" - "math/rand" "time" ) @@ -36,7 +34,7 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps time.After(5 * time.Second) // 首次刷新 if !c.IsFighting && c.MapId != 0 { - spawnMonsters(c) + data.SpawnMonsters(c, true) } //循环刷新怪物 @@ -51,7 +49,7 @@ func (h *Controller) MapEnter(data *maps.InInfo, c *entity.Player) (result *maps case <-ticker.C: // 刷新当前地图的怪物 if !c.IsFighting && c.MapId != 0 { - spawnMonsters(c) + data.SpawnMonsters(c, false) } } @@ -92,102 +90,3 @@ func (h *Controller) MapList(data *maps.ListMapPlayerInboundInfo, c *entity.Play result.Player = append(result.Player, *result1) return } - -// 刷怪具体实现 -func spawnMonsters(c *entity.Player) { - // 获取当前地图的怪物配置 - - if c == nil || mservice.NewMonsterService().GetId(c.MapId) == 0 { //用户离线 - return - } - if !c.IsLogin { - defer func() { - - if c.StopChan != nil { - close(c.StopChan) - c.StopChan = nil - } - }() - } - - // 创建数据包 - tt := handler.NewTomeeHeader(2004, c.UserID) - t1 := genMonster(c.MapId, generateThreeUniqueNumbers()) - - c.SendPack(tt.Pack(&t1)) -} - -// 应该根据怪物信息决定后端生成 -func genMonster(mapid uint32, wz [3]int) maps.OgreInfo { - // 设置怪物信息 - t1 := maps.OgreInfo{} - - for i := 0; i < 3; i++ { - - ttt := maps.OgrePetInfo{} - ttt.Id = mservice.NewMonsterService().GetId(mapid) //待修改成xml获取 - - ttt.Shiny = uint32(i + 1) //异色概率,待实现自定义 - //t1.Data[i] = mservice.NewMonsterService().GetId(c.MapId) - t1.Data[wz[i]] = ttt - } - - return t1 -} - -// 计算整数的二进制1的个数(Integer.bitCount) -func bitsCount(n int) int { - count := 0 - for n > 0 { - count += n & 1 - n >>= 1 - } - return count -} - -// 生成0-9之间三个不重复的随机数 进地图5s -func generateThreeUniqueNumbers() [3]int { - rand.Seed(time.Now().UnixNano()) - selected := make(map[int]bool) - var result [3]int - index := 0 - - for index < 3 { - num := rand.Intn(10) - if !selected[num] { - selected[num] = true - result[index] = num - index++ - } - } - return result -} - -// 从三个数字中移除一个,并从剩余6个数字中选一个补充 10s -func replaceOneNumber(original [3]int) ([3]int, int, int) { - // 随机选择要移除的索引(0-2) - removeIndex := rand.Intn(3) - removedNum := original[removeIndex] - - // 找出所有不在原始数组中的数字(候选数字) - candidates := []int{} - originalMap := make(map[int]bool) - for _, num := range original { - originalMap[num] = true - } - - for i := 0; i < 10; i++ { - if !originalMap[i] { - candidates = append(candidates, i) - } - } - - // 从候选数字中随机选择一个 - newNum := candidates[rand.Intn(len(candidates))] - - // 创建新数组并替换数字 - newNumbers := original - newNumbers[removeIndex] = newNum - - return newNumbers, removedNum, newNum -} diff --git a/logic/controller/task.go b/logic/controller/task.go index 4054928d3..a32ccdb44 100644 --- a/logic/controller/task.go +++ b/logic/controller/task.go @@ -16,7 +16,24 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *entity.Playe result = &task.AcceptTaskOutboundInfo{} result.TaskId = data.TaskId - service.NewTaskService(c.UserID).AcceptTask(data.TaskId) + service.NewTaskService(c.UserID).Exec(func(ttt map[uint32]model.TaskInfo) bool { + ft, ok := ttt[data.TaskId] + if ok { //如果找到任务 + if ft.Status == 0 { //可以接受 + ft.Status = 1 + return true + } else { + return false + } + } else { + ttt[data.TaskId] = model.TaskInfo{ + Status: 1, + } + + } + + return false + }) return result, 0 } @@ -25,8 +42,15 @@ func (h Controller) AcceptTask(data *task.AcceptTaskInboundInfo, c *entity.Playe * 更新任务步骤 */ func (h Controller) AddTaskBuf(data *task.AddTaskBufInboundInfo, c *entity.Player) (result *task.AddTaskBufOutboundInfo, err errorcode.ErrorCode) { + service.NewTaskService(c.UserID).Exec(func(ttt map[uint32]model.TaskInfo) bool { + if conditions, ok := ttt[data.TaskId]; ok { + conditions.TaskInfo = data.TaskList + ttt[data.TaskId] = conditions + return true + } - service.NewTaskService(c.UserID).AddTaskBuf(data.TaskId, model.TaskInfo{TaskInfo: data.TaskList, Status: 0}) + return false + }) return &task.AddTaskBufOutboundInfo{}, 0 } diff --git a/logic/service/fight/battle/node/Turn.go b/logic/service/fight/battle/node/Turn.go index 5ea67603b..10dbe06fe 100644 --- a/logic/service/fight/battle/node/Turn.go +++ b/logic/service/fight/battle/node/Turn.go @@ -11,11 +11,6 @@ func (this *EffectNode) OnTurnStart() bool { return true } -// 如果是次数类的,那就相当于重写回合结束计数器 -func (this *EffectNode) PreTurnEnd() bool { - panic("not implemented") // TODO: Implement -} - // 回合结束一次性effect清楚掉 func (this *EffectNode) TurnEnd() bool { diff --git a/logic/service/fight/battle/node/node.go b/logic/service/fight/battle/node/node.go index 1fd8352e9..e7d3279e9 100644 --- a/logic/service/fight/battle/node/node.go +++ b/logic/service/fight/battle/node/node.go @@ -69,8 +69,8 @@ func (this *EffectNode) GetSkill() *info.BattleSkillEntity { } // 获取对方精灵 -func (this *EffectNode) GetBattle() *info.BattleContainer1V1 { - pet, _ := this.ctx.Value(info.BattleContainerCtx).(*info.BattleContainer1V1) +func (this *EffectNode) GetBattle() *info.Battle1V1 { + pet, _ := this.ctx.Value(info.BattleContainerCtx).(*info.Battle1V1) return pet diff --git a/logic/service/fight/info/BattleSkillEntity.go b/logic/service/fight/info/BattleSkillEntity.go index 1c70a6411..abb1290a8 100644 --- a/logic/service/fight/info/BattleSkillEntity.go +++ b/logic/service/fight/info/BattleSkillEntity.go @@ -186,7 +186,7 @@ var DamageC = enum.New[struct { }]() func (s *BattleSkillEntity) Random() *random.RandomXS128 { - battle, _ := s.ctx.Value(BattleContainerCtx).(*BattleContainer1V1) + battle, _ := s.ctx.Value(BattleContainerCtx).(*Battle1V1) return battle.Rand diff --git a/logic/service/fight/info/battle.go b/logic/service/fight/info/battle.go index 043ffde98..51e9b1609 100644 --- a/logic/service/fight/info/battle.go +++ b/logic/service/fight/info/battle.go @@ -6,7 +6,7 @@ import ( "github.com/tnnmigga/enum" ) -type BattleContext struct { +type Battle struct { Rand *random.RandomXS128 //本次战斗随机数 same []BattleInputSourceEntity //同阵营 Round int //回合数 @@ -16,7 +16,7 @@ type BattleContext struct { } // 执行下一回合 -func (b *BattleContext) NextRound() { +func (b *Battle) NextRound() { b.Round++ //回合数加1 diff --git a/logic/service/fight/info/battle_1v1.go b/logic/service/fight/info/battle_1v1.go index f3e20b5dd..533773391 100644 --- a/logic/service/fight/info/battle_1v1.go +++ b/logic/service/fight/info/battle_1v1.go @@ -7,27 +7,27 @@ import ( "time" ) -type BattleContainer1V1 struct { - BattleContext +type Battle1V1 struct { + Battle Ownerid uint32 // 房主ID FirstPerson uint32 //先手方ID } // 返回房主信息 -func (b *BattleContainer1V1) Owner() *BattleInputSourceEntity { +func (b *Battle1V1) Owner() *BattleInputSourceEntity { return &b.same[0] } // 返回邀请者信息,比如野怪 -func (b *BattleContainer1V1) Target() *BattleInputSourceEntity { +func (b *Battle1V1) Target() *BattleInputSourceEntity { return &b.opposite[0] } -func NewBattleContainer1v1(i NoteReadyToFightInfo) *BattleContainer1V1 { +func NewBattleContainer1v1(i NoteReadyToFightInfo) *Battle1V1 { - ret := BattleContainer1V1{} + ret := Battle1V1{} ret.same = make([]BattleInputSourceEntity, 0) //初始化本阵营 ret.opposite = make([]BattleInputSourceEntity, 0) //初始化敌方阵营 diff --git a/logic/service/fight/info/nodemanger.go b/logic/service/fight/info/nodemanger.go index b2df2552d..8b4d3278a 100644 --- a/logic/service/fight/info/nodemanger.go +++ b/logic/service/fight/info/nodemanger.go @@ -30,8 +30,7 @@ type Effect interface { OnDefeat() bool // 精灵被击败时触发 - PreTurnEnd() bool // 回合结束前 - TurnEnd() bool // 回合结束 + TurnEnd() bool // 回合结束 // 堆叠(Stack)相关触发 OnStackBefore() bool // 堆叠效果前触发 diff --git a/logic/service/maps/Map_Ogre.go b/logic/service/maps/Map_Ogre.go index 2aa26e1e7..f937c5b8f 100644 --- a/logic/service/maps/Map_Ogre.go +++ b/logic/service/maps/Map_Ogre.go @@ -8,3 +8,4 @@ type OgrePetInfo struct { Id uint32 Shiny uint32 } + diff --git a/logic/service/maps/mapin.go b/logic/service/maps/mapin.go index b451f504f..48f1d63d6 100644 --- a/logic/service/maps/mapin.go +++ b/logic/service/maps/mapin.go @@ -5,6 +5,8 @@ import ( "blazing/common/socket/handler" "blazing/logic/service/space" "blazing/modules/blazing/model" + "math/rand" + "time" "github.com/creasty/defaults" ) @@ -16,8 +18,8 @@ type InInfo struct { MapId uint32 // Point: 直接给坐标x,y - Point model.Pos `fieldDesc:"直接给坐标x,y"` - + Point model.Pos `fieldDesc:"直接给坐标x,y"` + monsters [3]int // Reverse2: 暂定 占位字符2 //Reverse2 string `struc:"[2]byte"` } @@ -32,6 +34,112 @@ func (t *InInfo) Broadcast(mapid uint32, o OutInfo) { }) } +// 刷怪具体实现 +func (t *InInfo) SpawnMonsters(c *entity.Player, isfrist bool) { + // 获取当前地图的怪物配置 + + // if c == nil || mservice.NewMonsterService().GetId(c.MapId) == 0 { //用户离线 + // return + // } + if !c.IsLogin { + defer func() { + + if c.StopChan != nil { + close(c.StopChan) + c.StopChan = nil + } + }() + } + + // 创建数据包 + tt := handler.NewTomeeHeader(2004, c.UserID) + + if isfrist { + t.monsters = generateThreeUniqueNumbers() + } else { + + t.monsters, _, _ = replaceOneNumber(t.monsters) + } + t1 := t.genMonster(c.MapId) + + c.SendPack(tt.Pack(&t1)) +} + +// 应该根据怪物信息决定后端生成 +func (t *InInfo) genMonster(mapid uint32) OgreInfo { + // 设置怪物信息 + t1 := OgreInfo{} + + for i := 0; i < 3; i++ { + + ttt := OgrePetInfo{} + ttt.Id = mservice.NewMonsterService().GetId(mapid) //待修改成xml获取 + + ttt.Shiny = uint32(i + 1) //异色概率,待实现自定义 + //t1.Data[i] = mservice.NewMonsterService().GetId(c.MapId) + t1.Data[t.monsters[i]] = ttt + } + + return t1 +} + +// 计算整数的二进制1的个数(Integer.bitCount) +func bitsCount(n int) int { + count := 0 + for n > 0 { + count += n & 1 + n >>= 1 + } + return count +} + +// 生成0-9之间三个不重复的随机数 进地图5s +func generateThreeUniqueNumbers() [3]int { + rand.Seed(time.Now().UnixNano()) + selected := make(map[int]bool) + var result [3]int + index := 0 + + for index < 3 { + num := rand.Intn(10) + if !selected[num] { + selected[num] = true + result[index] = num + index++ + } + } + return result +} + +// 从三个数字中移除一个,并从剩余6个数字中选一个补充 10s +func replaceOneNumber(original [3]int) ([3]int, int, int) { + // 随机选择要移除的索引(0-2) + removeIndex := rand.Intn(3) + removedNum := original[removeIndex] + + // 找出所有不在原始数组中的数字(候选数字) + candidates := []int{} + originalMap := make(map[int]bool) + for _, num := range original { + originalMap[num] = true + } + + for i := 0; i < 10; i++ { + if !originalMap[i] { + candidates = append(candidates, i) + } + } + + // 从候选数字中随机选择一个 + newNum := candidates[rand.Intn(len(candidates))] + + // 创建新数组并替换数字 + newNumbers := original + newNumbers[removeIndex] = newNum + + return newNumbers, removedNum, newNum +} + // 这里存储星球的map //var planetmap utils.SyncMap[] //= space.NewSyncMap() diff --git a/modules/blazing/service/task.go b/modules/blazing/service/task.go index 6dc4e32b2..8f29f3629 100644 --- a/modules/blazing/service/task.go +++ b/modules/blazing/service/task.go @@ -31,46 +31,6 @@ func (s *TaskService) Exec(t func(map[uint32]model.TaskInfo) bool) (ret bool) { s.GetModel().Save(&tt) //退出时保存 return } -func (s *TaskService) AcceptTask(task uint32) (ret bool) { - - s.Exec(func(ttt map[uint32]model.TaskInfo) bool { - ft, ok := ttt[task] - if ok { //如果找到任务 - if ft.Status == 0 { //可以接受 - ft.Status = 1 - return true - } else { - return false - } - } else { - ttt[task] = model.TaskInfo{ - Status: 1, - } - - } - - return false - }) - - return ret -} - -/** - * 更新任务步骤 - */ -func (s *TaskService) AddTaskBuf(task uint32, info model.TaskInfo) bool { - - return s.Exec(func(ttt map[uint32]model.TaskInfo) bool { - if conditions, ok := ttt[task]; ok { - conditions.TaskInfo = info.TaskInfo - ttt[task] = conditions - return true - } - - return false - }) - -} /** * 完成任务