diff --git a/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java b/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java index b74008ea3d0a71cca7cf20a260c7b434bb6de876..25ecfdd269c343719126db4ce9329d8d2b446d7f 100644 --- a/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java +++ b/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java @@ -1,24 +1,16 @@ package net.lesscoding.service.impl; import cn.dev33.satoken.stp.StpUtil; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; -import net.lesscoding.entity.AccountPlayer; import net.lesscoding.entity.BattleProcess; -import net.lesscoding.entity.PlayerWeapon; -import net.lesscoding.entity.Weapon; import net.lesscoding.mapper.AccountPlayerMapper; import net.lesscoding.mapper.PlayerWeaponMapper; import net.lesscoding.model.Player; -import net.lesscoding.model.dto.AddExpDto; import net.lesscoding.model.dto.BattleDto; -import net.lesscoding.model.vo.AfterPlayerVo; -import net.lesscoding.service.AccountPlayerService; import net.lesscoding.service.BattleService; import net.lesscoding.utils.BattleUtil; import net.lesscoding.utils.ExpUtil; -import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -26,8 +18,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; -import java.util.function.Function; -import java.util.stream.Collectors; /** * @author eleven @@ -52,12 +42,17 @@ public class BattleServiceImpl implements BattleService { public Object doBattle(BattleDto dto) { List processList = new ArrayList<>(); Player reqAttack = dto.getAttacker(); + Player reqDefender = dto.getDefender(); if (reqAttack.getId() != null || StrUtil.isNotBlank(reqAttack.getMac())) { throw new RuntimeException("别用接口刷啊喂,如果是插件的话记得更新一下插件版本"); } - reqAttack.setAccountId(StpUtil.getLoginIdAsInt()); + int attackerLoginId = StpUtil.getLoginIdAsInt(); + if(attackerLoginId == reqDefender.getAccountId()) { + throw new RuntimeException("别用接口刷了还自己打自己啊喂!"); + } + reqAttack.setAccountId(attackerLoginId); Player attacker = playerMapper.getPlayerBaseAttr(reqAttack); - Player defender = playerMapper.getPlayerBaseAttr(dto.getDefender()); + Player defender = playerMapper.getPlayerBaseAttr(reqDefender); BattleUtil.doBattle(attacker, defender, processList, 1); processList.add(new BattleProcess( processList.size(), @@ -66,5 +61,4 @@ public class BattleServiceImpl implements BattleService { expUtil.addPlayerExp(attacker, defender, processList); return processList; } - }