back_recharge
zhangshanxue 2019-09-09 14:16:28 +08:00
commit d0728bae5f
5 changed files with 38 additions and 13 deletions

View File

@ -20,6 +20,8 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.protocols.SceneFight;
import com.ljsd.network.session.ISession;
import com.ljsd.network.session.OnlineUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
@ -27,7 +29,7 @@ import java.util.concurrent.*;
public class Scene implements Runnable{
private static final Logger LOGGER = LoggerFactory.getLogger(Scene.class);
private List<FutureResult> futureList = new ArrayList<>();
public static ExecutorService executorService = Executors.newFixedThreadPool(32);
private int roomId;

View File

@ -192,13 +192,15 @@ public abstract class SceneActor{
scene.processEventUpdate(EventType.SCENEACTORE_UPDATE,this.getId());
}
}else if(type == BufferType.REBIRTH.getType()){
Creature creature = (Creature) this;
if(getType() == ActorType.Monster){
Creature creature = (Creature) this;
creature.setPreMoveTimestamp(now);
}
stateType = StateType.MOVEABLE;
if(getType() == ActorType.Player){
//如果是玩家获得无敌buffer
creature.getLife().setCurHp(creature.getLife().getMaxMp());
addOrUpdateBuffer(new EffectBuffer(scene.getBufferId(),BufferType.INVINCIBLE.getType(),now,now+SBloodyBattleSetting.sBloodyBattleSetting.getInvincible(),id,id,-1));
stateType=StateType.INVINCIBLE;
}

View File

@ -53,13 +53,13 @@ public class BattleManager {
if(resultCode == 1){
rebirth(blueUserBloodySnpInfo);
blueCreature.setLife(new Life(blueCreature.getLife().getMaxMp(),blueCreature.getLife().getMaxMp()));
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult,redCreature);
return checkResult;
}
rebirth(redUserBloodySnpInfo);
redCreature.setLife(new Life(redCreature.getLife().getMaxMp(),redCreature.getLife().getMaxMp()));
afterBattleRecord(blueUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(blueUserBloodySnpInfo.getHeroAllAttributes(),checkResult,blueCreature);
return checkResult;
}
@ -82,7 +82,7 @@ public class BattleManager {
int[] checkResult = CheckFight.getInstance().checkFight(seed, SArenaSetting.getSArenaSetting().getMostTime(), getFightData, getOptionData, FightType.BloodyFight);
int resultCode = checkResult[0];
if(resultCode == 1){
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult);
afterBattleRecord(redUserBloodySnpInfo.getHeroAllAttributes(),checkResult,creature);
return checkResult;
}
rebirth(redUserBloodySnpInfo);
@ -106,15 +106,18 @@ public class BattleManager {
//战斗之后血量计算
public static Map<String, FamilyHeroInfo> afterBattleRecord(Map<String, FamilyHeroInfo> heroAttribute,int[] fightResult){
public static Map<String, FamilyHeroInfo> afterBattleRecord(Map<String, FamilyHeroInfo> heroAttribute,int[] fightResult,Creature creature){
int index = 2;
int remainHp = 0;
for (Map.Entry<String, FamilyHeroInfo> entry : heroAttribute.entrySet()) {
FamilyHeroInfo value = entry.getValue();
Map<Integer, Integer> attribute = value.getAttribute();
attribute.put(HeroAttributeEnum.CurHP.getPropertyId(), fightResult[index]);
value.setAttribute(attribute);
index++;
remainHp+=attribute.get(HeroAttributeEnum.CurHP.getPropertyId());
}
creature.getLife().setCurHp(remainHp);
return heroAttribute;
}
@ -126,6 +129,7 @@ public class BattleManager {
Integer maxHp = familyHeroInfo.getAttribute().get(HeroAttributeEnum.Hp.getPropertyId());
familyHeroInfo.getAttribute().put(HeroAttributeEnum.CurHP.getPropertyId(),maxHp);
}
}

View File

@ -24,6 +24,8 @@ import com.ljsd.jieling.util.CellUtil;
import com.ljsd.jieling.util.MathUtils;
import com.ljsd.jieling.util.MonsterUtil;
import com.ljsd.network.session.ISession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
@ -32,6 +34,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ScheduledThreadPoolExecutor;
public class SceneManager {
private static final Logger LOGGER = LoggerFactory.getLogger(SceneManager.class);
private static Map<Integer, Scene> sceneMap = new HashMap<>();
private static Map<Integer, Scene> sceneByUidMap = new HashMap<>();
@ -106,7 +109,7 @@ public class SceneManager {
createMonster(scene,-1);
sceneMap.put(room.getId(),scene);
System.out.println("create romm --- -"+room.getId());
}
public static void createMonster(Scene scene, int target) {
@ -149,8 +152,8 @@ public class SceneManager {
scene.addScenActor(sceneMonster);
monsterIndex++;
if(target!=-1){
System.out.println("find and break... " + monsterIndex);
break;
LOGGER.info("the roomId = {},the new monsterIndex={} " ,scene.getRoomId(), monsterIndex);
break;
}
}
}
@ -159,7 +162,7 @@ public class SceneManager {
public static void createMinear(Scene scene,int target,int nums){
//创建矿
System.out.println("target--" + target + "-- nums --" + nums);
LOGGER.info("the roomId = {},the mineral target ={},the nums = {} " ,scene.getRoomId(), target,nums);
SBloodyBattleSetting sBloodyBattleSetting = SBloodyBattleSetting.sBloodyBattleSetting;
Map<Integer, Integer> initializeMineMap = sBloodyBattleSetting.getInitializeMineMap();
Map<Integer, SCMap> scMap = SCMap.sCMap.get(bloodyMap.getMapId());
@ -167,7 +170,6 @@ public class SceneManager {
for(SceneActor sceneActor : scene.getSceneActorMap().values()){
excluIndexs.add(sceneActor.getPos());
}
System.out.println(excluIndexs);
for (Map.Entry<Integer, SCMap> entry : scMap.entrySet()) {
SCMap scMap1 = entry.getValue();
int event = scMap1.getEvent();
@ -184,10 +186,17 @@ public class SceneManager {
Set<Integer> cacheRemove = new HashSet<>();
while (nums -- >0){
int index = MathUtils.randomWeight(groups, randomIndex);
if(index == -1){
cacheRemove.add(index);
break;
}
int pos = CellUtil.xy2Pos(groups[index][0], groups[index][1]);
while(excluIndexs.contains(pos)){
cacheRemove.add(index);
index = MathUtils.randomWeight(groups, randomIndex);
if(index == -1){
break;
}
pos = CellUtil.xy2Pos(groups[index][0], groups[index][1]);
}
excluIndexs.add(pos);
@ -260,6 +269,10 @@ public class SceneManager {
Set<Integer> removeIndexs = new HashSet<>();
while (true){
int index= MathUtils.randomWeight(points,randomIndexs);
if(index ==-1){
removeIndexs.add(index);
break;
}
Set<Integer> cache = new HashSet<>();
int[] possiblePoint = points[index];
if( !CellUtil.calSurPos(possiblePoint[0],possiblePoint[1],sBloodyBattleSetting.getPointInterval(),maxX,maxY,cache) ){
@ -392,7 +405,7 @@ public class SceneManager {
scene.setState(1);
scene.setStartTime(System.currentTimeMillis());
scheduledExecutor.execute(scene);
System.out.println("start com.ljsd.battle pvp...........................");
LOGGER.info("the roomid={},start battle pvp",scene.getRoomId());
}

View File

@ -254,12 +254,16 @@ public class MathUtils {
public static int randomWeight(int[][] source,Set<Integer> excluIndexs){
int length = source.length;
int randomIndex = 0;
while (true){
int times=100;
while (times-->0){
randomIndex= randomInt(length);
if(!excluIndexs.contains(randomIndex)){
break;
}
}
if(times<=0){
return -1;
}
excluIndexs.add(randomIndex);
return randomIndex;
}