2025-08-24 17:33:19 +08:00
|
|
|
package controller
|
|
|
|
|
|
|
|
|
|
import (
|
2025-09-21 14:56:37 +00:00
|
|
|
"blazing/common/data/xmlres"
|
2025-08-24 17:33:19 +08:00
|
|
|
"blazing/common/socket/errorcode"
|
2025-09-04 02:00:57 +08:00
|
|
|
|
2025-08-24 17:33:19 +08:00
|
|
|
"blazing/logic/service/fight"
|
2025-08-25 04:23:32 +08:00
|
|
|
"blazing/logic/service/fight/info"
|
2025-09-14 01:35:16 +08:00
|
|
|
"blazing/logic/service/player"
|
2025-08-24 17:33:19 +08:00
|
|
|
"blazing/modules/blazing/model"
|
2025-10-22 21:30:05 +08:00
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
2025-08-24 17:33:19 +08:00
|
|
|
)
|
|
|
|
|
|
2025-09-25 14:51:11 +00:00
|
|
|
// 挑战地图boss
|
2025-09-19 00:29:55 +08:00
|
|
|
func (h Controller) PlayerFightBoss(data *fight.ChallengeBossInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-10-31 00:53:22 +08:00
|
|
|
if !c.CanFight() {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
2025-10-22 21:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 00:29:55 +08:00
|
|
|
var petid int
|
|
|
|
|
var mo *model.PetInfo
|
2025-10-22 21:30:05 +08:00
|
|
|
moinfo := &model.PlayerInfo{}
|
|
|
|
|
|
2025-09-21 14:56:37 +00:00
|
|
|
if c.Info.MapID == 515 && data.BossId == 0 { //说明是新手,随机生成
|
2025-09-19 00:29:55 +08:00
|
|
|
switch c.Info.PetList[0].ID {
|
|
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
petid = 4
|
|
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
|
petid = 1
|
|
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
|
petid = 7
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 18:51:41 +08:00
|
|
|
mo = c.GenPetInfo(
|
2025-09-20 13:12:45 +08:00
|
|
|
int(petid), 24, //24个体
|
|
|
|
|
-1,
|
|
|
|
|
0, //野怪没特性
|
|
|
|
|
0,
|
|
|
|
|
2)
|
2025-10-22 21:30:05 +08:00
|
|
|
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
|
|
|
|
moinfo.PetList = append(moinfo.PetList, *mo)
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
mdata, ok := xmlres.MonsterMap[int(c.Info.MapID)]
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2025-10-31 00:53:22 +08:00
|
|
|
if len(mdata.Bosses) == 0 {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2025-10-22 21:30:05 +08:00
|
|
|
for _, bc := range mdata.Bosses {
|
|
|
|
|
if bc.Id == nil {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if uint32(*bc.Id) == data.BossId {
|
|
|
|
|
for _, bm := range bc.BossMon {
|
|
|
|
|
mo = c.GenPetInfo(
|
|
|
|
|
gconv.Int(bm.MonID), 24, //24个体
|
|
|
|
|
-1,
|
|
|
|
|
0, //野怪没特性
|
|
|
|
|
0,
|
2025-11-07 22:50:34 +08:00
|
|
|
bm.Lv)
|
2025-10-22 21:30:05 +08:00
|
|
|
|
2025-11-07 22:50:34 +08:00
|
|
|
// mo.Level = uint32(bm.Lv)
|
2025-10-22 21:30:05 +08:00
|
|
|
mo.CalculatePetPane()
|
|
|
|
|
mo.Hp = uint32(bm.Hp)
|
|
|
|
|
mo.MaxHp = uint32(bm.Hp)
|
|
|
|
|
moinfo.PetList = append(moinfo.PetList, *mo)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
2025-11-02 18:56:16 +08:00
|
|
|
break
|
2025-10-22 21:30:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2025-09-19 00:29:55 +08:00
|
|
|
|
|
|
|
|
}
|
2025-10-22 21:30:05 +08:00
|
|
|
|
2025-09-21 14:56:37 +00:00
|
|
|
ai := player.NewAI_player(moinfo)
|
2025-09-25 14:51:11 +00:00
|
|
|
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_BOSS, c, ai)
|
2025-09-19 00:29:55 +08:00
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-09-20 13:12:45 +08:00
|
|
|
|
|
|
|
|
// 战斗野怪
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) OnPlayerFightNpcMonster(data *fight.FightNpcMonsterInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-10-31 00:53:22 +08:00
|
|
|
if !c.CanFight() {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
|
|
|
|
}
|
2025-09-02 00:45:29 +08:00
|
|
|
refpet := c.OgreInfo.Data[data.Number]
|
2025-09-06 00:31:08 +08:00
|
|
|
if refpet.Id == 0 {
|
2025-09-02 00:45:29 +08:00
|
|
|
|
2025-09-06 00:31:08 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotExists
|
|
|
|
|
}
|
2025-10-13 18:51:41 +08:00
|
|
|
mo := c.GenPetInfo(
|
2025-09-20 13:12:45 +08:00
|
|
|
int(refpet.Id), -1,
|
|
|
|
|
-1,
|
|
|
|
|
0, //野怪没特性
|
|
|
|
|
int(refpet.Shiny),
|
|
|
|
|
int(refpet.Lv))
|
2025-09-05 22:40:36 +08:00
|
|
|
|
|
|
|
|
if c.FightC != nil {
|
2025-09-06 00:31:08 +08:00
|
|
|
return nil, errorcode.ErrorCodes.ErrOnlineOver6HoursCannotFight
|
2025-09-05 22:40:36 +08:00
|
|
|
}
|
2025-09-21 14:56:37 +00:00
|
|
|
moinfo := &model.PlayerInfo{}
|
|
|
|
|
moinfo.Nick = xmlres.PetMAP[int(mo.ID)].DefName
|
|
|
|
|
moinfo.PetList = append(moinfo.PetList, *mo)
|
|
|
|
|
ai := player.NewAI_player(moinfo)
|
|
|
|
|
|
2025-09-25 14:51:11 +00:00
|
|
|
fight.NewFight(info.BattleMode.MULTI_MODE, info.BattleStatus.FIGHT_WITH_NPC, c, ai)
|
2025-09-06 00:31:08 +08:00
|
|
|
|
2025-08-24 17:33:19 +08:00
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-09-01 01:03:46 +08:00
|
|
|
|
|
|
|
|
// 准备战斗
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) OnReadyToFight(data *fight.ReadyToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-09-02 00:45:29 +08:00
|
|
|
|
2025-09-04 02:00:57 +08:00
|
|
|
c.FightC.ReadyFight(c)
|
2025-08-24 17:33:19 +08:00
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-08-27 05:10:10 +00:00
|
|
|
|
2025-09-01 01:03:46 +08:00
|
|
|
// 接收战斗或者取消战斗的包
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) OnPlayerHandleFightInvite(data *fight.HandleFightInviteInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-05 17:06:08 +00:00
|
|
|
|
2025-09-20 00:17:29 +08:00
|
|
|
if ok, p1 := c.AgreeBattle(data.UserID, data.Flag, data.Mode); ok {
|
2025-10-22 00:25:38 +08:00
|
|
|
fight.NewFight(data.Mode, info.BattleStatus.FIGHT_WITH_PLAYER, c, p1) ///开始对战,房主方以及被邀请方
|
2025-09-20 00:17:29 +08:00
|
|
|
}
|
2025-08-27 05:10:10 +00:00
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-09-01 01:03:46 +08:00
|
|
|
|
2025-09-20 00:17:29 +08:00
|
|
|
// 邀请其他人进行战斗
|
|
|
|
|
func (h Controller) OnPlayerInviteOtherFight(data *fight.InviteToFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-10-31 00:53:22 +08:00
|
|
|
if !c.CanFight() {
|
|
|
|
|
return nil, errorcode.ErrorCodes.ErrPokemonNotEligible
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-23 16:48:40 +00:00
|
|
|
c.InvitePlayerToBattle(&info.PVPinfo{PlayerID: data.UserID, Mode: data.Mode})
|
2025-09-20 00:17:29 +08:00
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-31 00:53:22 +08:00
|
|
|
// 取消和他人战斗
|
|
|
|
|
func (h Controller) OnPlayerCanceledOtherInviteFight(data *fight.InviteFightCancelInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
|
|
|
|
c.CancelBattle()
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 01:03:46 +08:00
|
|
|
// 使用技能包
|
2025-09-25 14:51:11 +00:00
|
|
|
func (h Controller) UseSkill(data *fight.UseSkillInInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-10-31 00:53:22 +08:00
|
|
|
if c.FightC != nil {
|
|
|
|
|
c.FightC.UseSkill(c, int32(data.SkillId))
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 01:03:46 +08:00
|
|
|
return nil, 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 战斗逃跑
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) Escape(data *fight.EscapeFightInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-05 17:19:09 +00:00
|
|
|
if c.FightC == nil {
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
|
|
|
|
}
|
|
|
|
|
if !c.FightC.CanEscape() {
|
|
|
|
|
|
|
|
|
|
return nil, 0
|
2025-11-05 13:37:01 +00:00
|
|
|
}
|
2025-11-05 17:19:09 +00:00
|
|
|
c.FightC.Over(c, info.BattleOverReason.PlayerEscape)
|
2025-09-01 01:03:46 +08:00
|
|
|
return nil, 0
|
|
|
|
|
}
|
2025-09-07 00:23:28 +08:00
|
|
|
|
|
|
|
|
// 切换精灵
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) ChangePet(data *fight.ChangePetInboundInfo, c *player.Player) (result *fight.NullOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-05 13:37:01 +00:00
|
|
|
if c.FightC != nil {
|
|
|
|
|
c.FightC.ChangePet(c, data.CatchTime)
|
|
|
|
|
}
|
2025-09-11 02:44:21 +08:00
|
|
|
return nil, -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 切换精灵
|
2025-09-14 01:35:16 +08:00
|
|
|
func (h Controller) Capture(data *fight.CatchMonsterInboundInfo, c *player.Player) (result *info.CatchMonsterOutboundInfo, err errorcode.ErrorCode) {
|
2025-09-11 02:44:21 +08:00
|
|
|
|
2025-10-26 20:56:03 +08:00
|
|
|
c.FightC.Capture(c, data.CapsuleId)
|
2025-09-11 02:44:21 +08:00
|
|
|
return nil, -1
|
2025-09-07 00:23:28 +08:00
|
|
|
}
|
2025-09-25 14:51:11 +00:00
|
|
|
|
2025-10-26 20:56:03 +08:00
|
|
|
// 加载进度
|
2025-09-25 14:51:11 +00:00
|
|
|
func (h Controller) LoadPercent(data *fight.LoadPercentInboundInfo, c *player.Player) (result *info.LoadPercentOutboundInfo, err errorcode.ErrorCode) {
|
2025-11-01 00:40:19 +08:00
|
|
|
if c.FightC != nil {
|
|
|
|
|
|
|
|
|
|
c.FightC.LoadPercent(c, int32(data.Percent))
|
|
|
|
|
}
|
2025-09-25 14:51:11 +00:00
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
}
|
2025-11-08 16:38:41 +08:00
|
|
|
func (h Controller) UsePetItemInboundInfo(data *fight.UsePetItemInboundInfo, c *player.Player) (result *info.UsePetIteminfo, err errorcode.ErrorCode) {
|
2025-11-08 01:30:53 +08:00
|
|
|
if c.FightC != nil {
|
|
|
|
|
|
|
|
|
|
c.FightC.UseItem(c, data.CatchTime, data.ItemId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, -1
|
|
|
|
|
}
|