This commit is contained in:
DESKTOP-5RP3AKU\Jisol 2023-11-28 02:38:46 +08:00
parent 07db3912cc
commit 5a9ab02b54
3 changed files with 44 additions and 13 deletions

View File

@ -107,11 +107,13 @@ export default class GOnHookManager extends Singleton{
//删除 //删除
this.killSreeps.splice(index,1); this.killSreeps.splice(index,1);
//通知添加野怪被删除
app.event.emit(GOnHookManagerEvent.DEL_KILL_SREEP,creeps); app.event.emit(GOnHookManagerEvent.DEL_KILL_SREEP,creeps);
// //通知添加野怪被删除
// if(await GAPI.GOnHookSellCreeps(creeps.key)){
// return true;
// }else{
// }
return await GAPI.GOnHookSellCreeps(creeps.key); return await GAPI.GOnHookSellCreeps(creeps.key);
} }
} }

View File

@ -21,6 +21,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.retry.RetryException;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -98,9 +99,17 @@ public class GOnHookController {
//找到野怪删除 //找到野怪删除
if(Objects.isNull(creeps = CREEPS.get(player.getPlayerId()))) return NewsResource.onFail("卖出失败",false); if(Objects.isNull(creeps = CREEPS.get(player.getPlayerId()))) return NewsResource.onFail("卖出失败",false);
if(Objects.nonNull(creeps.remove(creepId))){ GOnHookMessage.GOnHookPet onHookPet = creeps.remove(creepId);
if(Objects.nonNull(onHookPet)){
Resource res;
//增加玩家金币 (默认添加100) //增加玩家金币 (默认添加100)
Resource res = resourceService.addResourceValue(player.getPlayerId(), ResourceId.Gold.id, 100L); try{
res = resourceService.addResourceValue(player.getPlayerId(), ResourceId.Gold.id, 100L);
}catch (RetryException e){
//出售失败
creeps.put(creepId,onHookPet); //放回去
throw new RetryException("");
}
return NewsResource.onSuccess( return NewsResource.onSuccess(
"卖出成功", "卖出成功",
true, true,

View File

@ -40,6 +40,24 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
res = this.initResource(playerId,type); res = this.initResource(playerId,type);
} }
if(value > 0){
//如果是累加 执行累加sql
if(this.update(
Wrappers.lambdaUpdate(Resource.class)
.eq(Resource::getPlayerId, playerId) //玩家
.eq(Resource::getResourceTbId, type) //资源
.setSql("resource_value = resource_value + "+value)
)){
//添加资源
res.setResourceValue(res.getResourceValue() + value);
return res;
}else{
throw new RetryException("");
}
}else{
//添加资源 //添加资源
res.setResourceValue(res.getResourceValue() + value); res.setResourceValue(res.getResourceValue() + value);
@ -53,6 +71,8 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
return res; return res;
} }
}
//初始化某个资源 //初始化某个资源
@Override @Override
public Resource initResource(Long playerId, int type) { public Resource initResource(Long playerId, int type) {