探索 战斗

back_recharge
xuexinpeng 2021-12-21 19:04:56 +08:00
parent 9253e775f0
commit e683d993d5
3 changed files with 154 additions and 95 deletions

View File

@ -1,10 +1,15 @@
package com.ljsd.jieling.handler.explorerMap;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.ExplorerInfo;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.network.session.ISession;
import rpc.protocols.MessageTypeProto;
import rpc.protocols.PlayerInfoProto;
import java.util.Map;
public class ExplorerMapInfoHandler extends BaseHandler<PlayerInfoProto.ExplorerMapInfoRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
@ -13,6 +18,16 @@ public class ExplorerMapInfoHandler extends BaseHandler<PlayerInfoProto.Explore
@Override
public void processWithProto(ISession session, PlayerInfoProto.ExplorerMapInfoRequest proto) throws Exception{
int uid = session.getUid();
User user = UserManager.getUser(uid);
if (user == null) {
return;
}
Map<Integer, ExplorerInfo> explorer = user.getPlayerInfoManager().getExplorer();

View File

@ -5,13 +5,10 @@ import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.activity.crossService.CrossServiceLogic;
import com.ljsd.jieling.logic.dao.ExplorerInfo;
import com.ljsd.jieling.logic.dao.PlayerManager;
import com.ljsd.jieling.logic.dao.TeamEnum;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.cross.CSPlayer;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic;
import config.SArenaRobotConfig;
import config.SExplore;
import config.SExploreFight;
import manager.STableManager;
@ -20,130 +17,168 @@ import org.slf4j.LoggerFactory;
import rpc.protocols.CommonProto;
import util.TimeUtils;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class ExplorerMapLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(ExplorerMapLogic.class);
public ExplorerMapLogic(){
public ExplorerMapLogic() {
}
public static ExplorerMapLogic getInstance() {
return ExplorerMapLogic.Instance.instance;
}
public static class Instance {
public final static ExplorerMapLogic instance = new ExplorerMapLogic();
}
//战斗 派遣
public static void battle(User user, int mapId, int teamId){
public static void battle(User user, int mapId, int teamId) {
RedisUtil redisUtil = RedisUtil.getInstence();
String key2 = RedisKey.getKey(RedisKey.EXPLORER_MAP_PLAYER, String.valueOf(mapId), false);
redisUtil.lSet(key2, String.valueOf(user.getId()));
}
public static void battle(User user){
public static void battle(User user) {
Map<Integer, ExplorerInfo> explorer = user.getPlayerInfoManager().getExplorer();
}
//单场战斗
public static void singleBattle(User user,int teamId){
ExplorerInfo explorerInfo = user.getPlayerInfoManager().getExplorer().get(teamId);
if(explorerInfo == null){
public static void calOfflineReward(User user){
//计算离线奖励
Map<Integer, ExplorerInfo> explorer = user.getPlayerInfoManager().getExplorer();
if (explorer == null || explorer.size() == 0) {
return;
}
if(explorerInfo.getPlayerHp()!=0 && explorerInfo.getEnemyHp()!=0){
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user,teamId, false);
SExplore exploreConfig = STableManager.getConfig(SExplore.class).get(explorerInfo.getMapId());
if(exploreConfig == null){
return;
}
//怪物的初始血量
int mapMonsterForce = exploreConfig.getMonsterForce();
float ratio = (float)teamForce/mapMonsterForce;
SExploreFight exploreFightData = SExploreFight.getConfigByFightDownAndFightUp(ratio);
if(exploreFightData == null){
return;
}
//掉血比例
float reduceRatio = exploreFightData.getLoseFight();
//玩家掉血
explorerInfo.setPlayerHp(explorerInfo.getPlayerHp() - (int)(explorerInfo.getPlayerHp()*reduceRatio));
//怪物掉血
explorerInfo.setEnemyHp(explorerInfo.getEnemyHp()- (int)(explorerInfo.getEnemyHp()*reduceRatio));
//玩家死亡 设置重生时间
if(explorerInfo.getPlayerHp() == 0){
explorerInfo.setPlayerReliveTime(TimeUtils.nowInt()+300);
}
//怪物死亡 设置重生时间
if(explorerInfo.getEnemyHp() == 0){
explorerInfo.setEnemyReliveTime(TimeUtils.nowInt()+300);
//胜利添加掉落
List<Integer>dropList = explorerInfo.getDropList();
if(dropList == null){
dropList = new ArrayList<>();
}
dropList.add(exploreConfig.getReward());
}
}
int offlineTime = (int)(user.getPlayerInfoManager().getOffLineTime()/1000);
for (Map.Entry<Integer, ExplorerInfo> keyVal : explorer.entrySet()){
while (keyVal.getValue().getPlayerReliveTime()< offlineTime && keyVal.getValue().getEnemyReliveTime()< offlineTime){
//打完架后 必定有一方没血
if(keyVal.getValue().getPlayerHp() == 0){
//直接满血复活
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user, keyVal.getKey(), false);
if(TimeUtils.nowInt()> keyVal.getValue().getPlayerReliveTime()+300){
keyVal.getValue().setPlayerReliveTime(keyVal.getValue().getPlayerReliveTime()+300);
keyVal.getValue().setPlayerHp(teamForce);
}
}
if(keyVal.getValue().getEnemyHp() == 0){
if(TimeUtils.nowInt()> keyVal.getValue().getEnemyReliveTime()+300){
keyVal.getValue().setEnemyReliveTime(keyVal.getValue().getEnemyReliveTime()+300);
SExplore exploreConfig = STableManager.getConfig(SExplore.class).get(keyVal.getValue().getMapId());
if (exploreConfig == null) {
continue;
}
//怪物的初始血量
int mapMonsterForce = exploreConfig.getMonsterForce();
keyVal.getValue().setEnemyHp(mapMonsterForce);
}
}
//打架
singleBattle(user,keyVal.getKey());
}
}
}
//复活怪物 自己血量之类的
public static void recycleFight(){
try{
Set<Integer> uids = OnlineUserManager.sessionMap.keySet();
for(int uid:uids){
User user = UserManager.getUser(uid);
Map<Integer,ExplorerInfo> explorer = user.getPlayerInfoManager().getExplorer();
if(explorer == null || explorer.size() == 0){
continue;
}
List<Integer> delayId = new ArrayList<>();
for (Map.Entry<Integer, ExplorerInfo> keyVal:explorer.entrySet()){
//到期探索
if(keyVal.getValue().getSendEndTime()<TimeUtils.now()){
delayId.add(keyVal.getKey());
}
//复活
//复活玩家
if(keyVal.getValue().getPlayerHp() == 0 && keyVal.getValue().getPlayerReliveTime()>= TimeUtils.nowInt()){
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user,keyVal.getKey(), false);
keyVal.getValue().setPlayerHp(teamForce);
//打架 TODO
singleBattle(user,keyVal.getKey());
}
//复活怪物
if(keyVal.getValue().getEnemyHp() == 0 && keyVal.getValue().getEnemyReliveTime()>= TimeUtils.nowInt()){
SExplore exploreConfig = STableManager.getConfig(SExplore.class).get(keyVal.getValue().getMapId());
if(exploreConfig == null){
continue;
}
//怪物的初始血量
int mapMonsterForce = exploreConfig.getMonsterForce();
keyVal.getValue().setEnemyHp(mapMonsterForce);
//打架 TODO
singleBattle(user,keyVal.getKey());
}
}
for(int id :delayId){
explorer.remove(id);
}
//探索队伍 map <id,(派遣到哪个地图里,派遣的截止时间,玩家,复活时间)>
//地图怪物 map<地图id,List<>()地图上所有的怪物怪物id,刷新时间,血量)>
//单场战斗
public static void singleBattle(User user, int teamId) {
ExplorerInfo explorerInfo = user.getPlayerInfoManager().getExplorer().get(teamId);
if (explorerInfo == null) {
return;
}
}catch (Exception e){
//if(explorerInfo.getPlayerHp()!=0 && explorerInfo.getEnemyHp()!=0){
while (explorerInfo.getPlayerHp() != 0 && explorerInfo.getEnemyHp() != 0)
{
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user, teamId, false);
SExplore exploreConfig = STableManager.getConfig(SExplore.class).get(explorerInfo.getMapId());
if (exploreConfig == null) {
return;
}
//怪物的初始血量
int mapMonsterForce = exploreConfig.getMonsterForce();
float ratio = (float) teamForce / mapMonsterForce;
SExploreFight exploreFightData = SExploreFight.getConfigByFightDownAndFightUp(ratio);
if (exploreFightData == null) {
return;
}
//掉血比例
float reduceRatio = exploreFightData.getLoseFight();
//玩家掉血
explorerInfo.setPlayerHp(explorerInfo.getPlayerHp() - (int) (explorerInfo.getPlayerHp() * reduceRatio));
//怪物掉血
explorerInfo.setEnemyHp(explorerInfo.getEnemyHp() - (int) (explorerInfo.getEnemyHp() * reduceRatio));
//玩家死亡 设置重生时间
if (explorerInfo.getPlayerHp() == 0) {
explorerInfo.setPlayerReliveTime(TimeUtils.nowInt() + 300);
}
//怪物死亡 设置重生时间
if (explorerInfo.getEnemyHp() == 0) {
explorerInfo.setEnemyReliveTime(TimeUtils.nowInt() + 300);
//胜利添加掉落
List<Integer> dropList = explorerInfo.getDropList();
if (dropList == null) {
dropList = new ArrayList<>();
}
dropList.add(exploreConfig.getReward());
}
}
}
//复活怪物 自己血量之类的 在线每分钟监听
public static void recycleFight() {
try {
Set<Integer> uids = OnlineUserManager.sessionMap.keySet();
for (int uid : uids) {
User user = UserManager.getUser(uid);
Map<Integer, ExplorerInfo> explorer = user.getPlayerInfoManager().getExplorer();
if (explorer == null || explorer.size() == 0) {
continue;
}
List<Integer> delayId = new ArrayList<>();
for (Map.Entry<Integer, ExplorerInfo> keyVal : explorer.entrySet()) {
//到期探索
if (keyVal.getValue().getSendEndTime() < TimeUtils.now()) {
delayId.add(keyVal.getKey());
}
//复活
//复活玩家
if (keyVal.getValue().getPlayerHp() == 0 && keyVal.getValue().getPlayerReliveTime() >= TimeUtils.nowInt()) {
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user, keyVal.getKey(), false);
keyVal.getValue().setPlayerHp(teamForce);
//打架 TODO
singleBattle(user, keyVal.getKey());
}
//复活怪物
if (keyVal.getValue().getEnemyHp() == 0 && keyVal.getValue().getEnemyReliveTime() >= TimeUtils.nowInt()) {
SExplore exploreConfig = STableManager.getConfig(SExplore.class).get(keyVal.getValue().getMapId());
if (exploreConfig == null) {
continue;
}
//怪物的初始血量
int mapMonsterForce = exploreConfig.getMonsterForce();
keyVal.getValue().setEnemyHp(mapMonsterForce);
//打架 TODO
singleBattle(user, keyVal.getKey());
}
}
for (int id : delayId) {
explorer.remove(id);
}
//探索队伍 map <id,(派遣到哪个地图里,派遣的截止时间,玩家,复活时间)>
//地图怪物 map<地图id,List<>()地图上所有的怪物怪物id,刷新时间,血量)>
}
} catch (Exception e) {
e.printStackTrace();
}
}
//怪物刷新
//邮件结算
/**
*
*/
@ -171,4 +206,11 @@ public class ExplorerMapLogic {
.setHeadFrame(csPlayer.getHeadFrame())
.build();
}
//怪物刷新
//邮件结算
public static class Instance {
public final static ExplorerMapLogic instance = new ExplorerMapLogic();
}
}

View File

@ -99,6 +99,7 @@ public class FightDataUtil {
SCHero hero = SCHero.getsCHero().get(sMonster.getMonsterId());
if(hero!=null){
unitData.set("job",hero.getJob());
unitData.set("star",hero.getStar());
}
if (unitSkill.length==1){
unitData.set("skill", getSkill(unitSkill[0],sMonster.getSkinId()));
@ -389,6 +390,7 @@ public class FightDataUtil {
unitData.set("property", getProperty(property));
unitData.set("skinId",data.getSkinId());
unitData.set("job",hero.getJob());
unitData.set("star",data.getStar());
return unitData;
}