From 6a839586a9cf6aa4c06b7e2363c415e316ff3372 Mon Sep 17 00:00:00 2001 From: TanYuan Date: Wed, 8 Nov 2023 10:00:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=97=B6=E8=87=AA=E5=B7=B1=E6=94=BB=E5=87=BB=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=9A=84=E6=83=85=E5=86=B5=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E6=B6=88=E8=80=97=E4=B8=80=E4=BB=BD=E4=BD=93=E5=8A=9B=EF=BC=8C?= =?UTF-8?q?=E6=8B=BF=E4=B8=A4=E4=BB=BD=E7=BB=8F=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BattleServiceImpl.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java b/src/main/java/net/lesscoding/service/impl/BattleServiceImpl.java index b74008e..25ecfdd 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; } - } -- Gitee