装备特性随机提交

back_recharge
lvxinran 2019-07-12 10:19:23 +08:00
parent 3b2ebae2c5
commit 98e2309523
6 changed files with 65 additions and 19 deletions

View File

@ -20,13 +20,13 @@ public class SEquipConfig implements BaseConfig {
private int[] propertyMax;
private int pool;
private int[] pool;
private int secondNumMin;
private int secondNumMax;
private int skillId;
private int[] skillPoolId;
private int quality;
@ -66,7 +66,7 @@ public class SEquipConfig implements BaseConfig {
return propertyMax;
}
public int getPool() {
public int[] getPool() {
return pool;
}
@ -78,11 +78,11 @@ public class SEquipConfig implements BaseConfig {
return secondNumMax;
}
public int getSkillId() {
return skillId;
public int[] getSkillPoolId() {
return skillPoolId;
}
public int getIfClear() {
public int getIfClear() {
return ifClear;
}

View File

@ -14,7 +14,11 @@ public class SPassiveSkillLogicConfig implements BaseConfig {
private float[] value;
private static Map<Integer, SPassiveSkillLogicConfig> config;
private int poolNum;
private int weight;
public static Map<Integer, SPassiveSkillLogicConfig> config;
@Override
public void init() throws Exception {
@ -37,5 +41,11 @@ public class SPassiveSkillLogicConfig implements BaseConfig {
return value;
}
public int getPoolNum() {
return poolNum;
}
public int getWeight() {
return weight;
}
}

View File

@ -10,9 +10,7 @@ import com.ljsd.jieling.util.TimeUtils;
import com.ljsd.jieling.util.UUIDEnum;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class Equip extends MongoBase implements Cloneable{
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(Equip.class);
@ -35,6 +33,7 @@ public class Equip extends MongoBase implements Cloneable{
private int createTime;
private int skill;
public Equip() {
this.setRootCollection(User._COLLECTION_NAME);
@ -65,6 +64,9 @@ public class Equip extends MongoBase implements Cloneable{
int secondValue = MathUtils.random(secondNumMin, secondNumMax);
this.secondValueByIdMap = getSecondValue(sEquipConfig.getPool(), secondValue,promoteMap);
this.createTime = (int)(TimeUtils.now()/1000);
//skill库随机
this.skill = getRandomSkill(sEquipConfig.getSkillPoolId());
}
//锻造
@ -91,6 +93,7 @@ public class Equip extends MongoBase implements Cloneable{
this.propertyValueByIdMap.put(properTyId,finalProperValue);
setForRunnes(runneIds,promoteMap);
this.createTime = (int)(TimeUtils.now()/1000);
this.skill = getRandomSkill(sEquipConfig.getSkillPoolId());
}
@ -150,9 +153,12 @@ public class Equip extends MongoBase implements Cloneable{
}
}
private Map<Integer,Integer> getSecondValue(int poolId,int nums,Map<Integer, Integer> promoteMap){
private Map<Integer,Integer> getSecondValue(int[] poolId,int nums,Map<Integer, Integer> promoteMap){
Map<Integer,Integer> result = new HashMap<>();
List<SEquipPropertyPool> sEquipPropertyPoolList = SEquipPropertyPool.getSEquipPropertyPool(poolId);
List<SEquipPropertyPool> sEquipPropertyPoolList = new ArrayList<>();
for(Integer pid:poolId){
sEquipPropertyPoolList.addAll(SEquipPropertyPool.getSEquipPropertyPool(pid));
}
if(sEquipPropertyPoolList.size()<nums){
LOGGER.error("the equip config is wrong,the equipTid={},the poolId={},the poolNum={},the requireNum={}",equipId,poolId,sEquipPropertyPoolList.size(),nums);
return result;
@ -195,7 +201,25 @@ public class Equip extends MongoBase implements Cloneable{
}
return result;
}
private int getRandomSkill(int[] skills){
if(skills.length<0){
return 0;
}
int poolId = MathUtils.randomFromArray(skills);
if(poolId==0){
return 0;
}
Iterator<SPassiveSkillLogicConfig> it = SPassiveSkillLogicConfig.config.values().iterator();
List<int[]> skillData = new ArrayList<>();
while (it.hasNext()){
SPassiveSkillLogicConfig next = it.next();
if(next.getPoolNum()==poolId&&next.getWeight()!=0) {
skillData.add(new int[]{next.getId(), next.getWeight()});
}
}
int[][] skillWeight = skillData.toArray(new int[skillData.size()][2]);
return MathUtils.randomFromWeight(skillWeight);
}
public void rebuildEquip(int workShopLevle){
SEquipConfig sEquipConfig = SEquipConfig.getsEquipConfigById(this.equipId);
int properTyId = sEquipConfig.getPropertyMin()[0];
@ -218,8 +242,10 @@ public class Equip extends MongoBase implements Cloneable{
int finalProperValue = MathUtils.random(properMinNum * (100 + propertyPromote) / 100, properMaxNum* (100 + propertyPromote) / 100);
this.propertyValueByIdMap.put(properTyId,finalProperValue);
}
List<SEquipPropertyPool> sEquipPropertyPoolList = SEquipPropertyPool.getSEquipPropertyPool(sEquipConfig.getPool());
List<SEquipPropertyPool> sEquipPropertyPoolList = new ArrayList<>();
for(Integer equipPool:sEquipConfig.getPool()){
sEquipPropertyPoolList.addAll(SEquipPropertyPool.getSEquipPropertyPool(equipPool));
}
for(SEquipPropertyPool sEquipPropertyPool : sEquipPropertyPoolList){
int secondPropertyId = sEquipPropertyPool.getPropertyId();
if(!secondValueByIdMap.containsKey(secondPropertyId)){
@ -314,4 +340,9 @@ public class Equip extends MongoBase implements Cloneable{
public int getCreateTime() {
return createTime;
}
public int getSkill() {
return skill;
}
}

View File

@ -763,9 +763,7 @@ public class HeroLogic {
if(StringUtil.isEmpty(equipId)){
continue;
}
int equipTid = equipMap.get(equipId).getEquipId();
SEquipConfig sEquipConfig = SEquipConfig.getsEquipConfigById(equipTid);
int skillId = sEquipConfig.getSkillId();
int skillId = equipMap.get(equipId).getSkill();
if(skillId!=0){
sb.append(skillId).append(DIVISION);
}

View File

@ -109,6 +109,7 @@ public class CBean2Proto {
.addAllSecondAttribute(parseFromMap(secondValueByIdMap))
.setRebuildLevel(equip.getRebuildLevel())
.setCreateTime(equip.getCreateTime())
.setSkillId(equip.getSkill())
.build();
return equipProto;
}

View File

@ -25,7 +25,7 @@ public class MathUtils {
public static void main(String [] args){
for (int i = 0 ; i <100;i++){
System.out.println(randomInt(100));
System.out.println(randomInt(10));
}
}
public static int randomForStrArray(String [] rateArray) {
@ -168,5 +168,11 @@ public class MathUtils {
}
return result;
}
public static int randomFromArray(int[] array){
if(array.length>1){
return array[randomInt(array.length-1)];
}
return 0;
}
}