阵容 装备

back_recharge
wangyuan 2019-02-18 18:42:09 +08:00
parent a60edcf3dd
commit ae84d45e79
8 changed files with 200 additions and 39 deletions

View File

@ -4,6 +4,7 @@ package com.ljsd.common.mogodb;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
import java.lang.reflect.*;
import java.util.*;
@ -234,7 +235,24 @@ public class BeanUtil {
Map map = new HashMap<K, V>();
BasicDBObject dbObj = (BasicDBObject)dbObject;
for (Map.Entry<String, Object> entry : dbObj.entrySet()) {
Object obj = getObj(entry.getValue(), (Class)types[1], root);
Type type = types[1];
if(type.getClass()== ParameterizedTypeImpl.class){
Class actualTypeArgument = (Class) (((ParameterizedTypeImpl) type).getActualTypeArguments()[0]);
ArrayList<Object> objects = new ArrayList<>();
BasicDBList values = (BasicDBList)entry.getValue();
Iterator<Object> iterator = values.iterator();
while (iterator.hasNext()){
Object next = iterator.next();
Object obj = getObj(next,actualTypeArgument, root);
objects.add(obj);
}
Object key = getKey(entry.getKey(), (Class)types[0]);
map.put(key,objects);
return map;
}
Object obj = getObj(entry.getValue(), (Class)type, root);
// Object value = ((Class)types[1]).newInstance();
// Object obj = dbObject2Bean((DBObject) entry.getValue(), value, root);
Object key = getKey(entry.getKey(), (Class)types[0]);

View File

@ -0,0 +1,20 @@
package com.ljsd.jieling.handler;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.netty.cocdex.PacketNetData;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.protocols.MessageTypeProto;
import org.springframework.stereotype.Component;
@Component
public class GetAllEquipHandler extends BaseHandler{
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.GET_ALL_EQUIP_REQUEST;
}
@Override
public void process(ISession iSession, PacketNetData netData) throws Exception {
HeroLogic.getInstance().getAllEquipInfo(iSession);
}
}

View File

@ -22,8 +22,8 @@ public class SaveTeamPosHandler extends BaseHandler{
HeroInfoProto.TeamposSaveRequest teamposSaveRequest = HeroInfoProto.TeamposSaveRequest.parseFrom(netData.parseClientProtoNetData());
CommonProto.TeamPosInfo teamPosInfo = teamposSaveRequest.getTeamPosInfo();
int teamId = teamPosInfo.getTeamId();
List<String> heroIdsList = teamPosInfo.getHeroIdsList();
List<Integer> pokemonIdsList = teamPosInfo.getPokemonIdsList();
HeroLogic.getInstance().saveTeamPos(iSession,teamId,heroIdsList,pokemonIdsList);
List<CommonProto.TeamHeroInfo> teamHeroInfosList = teamPosInfo.getTeamHeroInfosList();
List<CommonProto.TeamPokemonInfo> teamPokemonInfosList = teamPosInfo.getTeamPokemonInfosList();
HeroLogic.getInstance().saveTeamPos(iSession,teamId,teamHeroInfosList,teamPokemonInfosList);
}
}

View File

@ -0,0 +1,32 @@
package com.ljsd.jieling.logic.dao;
public class TeamPosForPokenInfo {
private int position;
private int pokenId;
public TeamPosForPokenInfo(){
}
public TeamPosForPokenInfo(int position, int pokenId) {
this.position = position;
this.pokenId = pokenId;
}
public int getPokenId() {
return pokenId;
}
public void setPokenId(int pokenId) {
this.pokenId = pokenId;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}

View File

@ -0,0 +1,31 @@
package com.ljsd.jieling.logic.dao;
public class TeamPosHeroInfo {
private String heroId;
private int position;
public TeamPosHeroInfo(){
}
public TeamPosHeroInfo(String heroId, int position) {
this.heroId = heroId;
this.position = position;
}
public String getHeroId() {
return heroId;
}
public void setHeroId(String heroId) {
this.heroId = heroId;
}
public int getPosition() {
return position;
}
public void setPosition(int position) {
this.position = position;
}
}

View File

@ -1,16 +1,18 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.common.mogodb.MongoBase;
import com.ljsd.jieling.protocols.CommonProto;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TeamPosManager extends MongoBase {
private Map<Integer, List<String>> teamPosForHero;
private Map<Integer, List<TeamPosHeroInfo>> teamPosForHero;
private Map<Integer,String> teamNames;
private Map<Integer,List<Integer>> teamPosForPoken;
private Map<Integer,List<TeamPosForPokenInfo>> teamPosForPoken;
public TeamPosManager(){
teamNames = new HashMap<>(3);
@ -23,23 +25,34 @@ public class TeamPosManager extends MongoBase {
updateString("teamNames",teamNames);
}
public void changeTeamInfo(int teamId,List<String> heroIds,List<Integer> pokemonoIds) throws Exception {
teamPosForHero.put(teamId,heroIds);
teamPosForPoken.put(teamId,pokemonoIds);
public void changeTeamInfo(int teamId, List<CommonProto.TeamHeroInfo> heroIds, List<CommonProto.TeamPokemonInfo> pokemonoIds) throws Exception {
List<TeamPosHeroInfo> teamPosHeroInfoList = new ArrayList<>(5);
for(CommonProto.TeamHeroInfo teamHeroInfo : heroIds){
TeamPosHeroInfo teamPosHeroInfo = new TeamPosHeroInfo(teamHeroInfo.getHeroId(), teamHeroInfo.getPosition());
teamPosHeroInfoList.add(teamPosHeroInfo);
}
List<TeamPosForPokenInfo> teamPosForPokenInfos = new ArrayList<>(5);
for(CommonProto.TeamPokemonInfo teamPokemonInfo : pokemonoIds){
teamPosForPokenInfos.add(new TeamPosForPokenInfo(teamPokemonInfo.getPosition(),teamPokemonInfo.getPokemonId()));
}
teamPosForHero.put(teamId,teamPosHeroInfoList);
teamPosForPoken.put(teamId,teamPosForPokenInfos);
updateString("teamPosForHero",teamPosForHero);
updateString("teamPosForPoken",teamPosForPoken);
}
public Map<Integer, List<String>> getTeamPosForHero() {
return teamPosForHero;
}
public Map<Integer, String> getTeamNames() {
return teamNames;
}
public Map<Integer, List<Integer>> getTeamPosForPoken() {
public Map<Integer, List<TeamPosHeroInfo>> getTeamPosForHero() {
return teamPosForHero;
}
public Map<Integer, List<TeamPosForPokenInfo>> getTeamPosForPoken() {
return teamPosForPoken;
}
}

View File

@ -20,6 +20,17 @@ public class HeroLogic {
private HeroLogic(){}
public void getAllEquipInfo(ISession iSession) throws Exception {
int uid = iSession.getUid();
User user = UserManager.getUser(uid);
Map<String, Equip> equipMap = user.getEquipManager().getEquipMap();
List<CommonProto.Equip> equipList = new ArrayList<>();
for(Equip equipInfo: equipMap.values()){
equipList.add(CBean2Proto.getEquipProto(equipInfo));
}
HeroInfoProto.GetAllEquipResponse build = HeroInfoProto.GetAllEquipResponse.newBuilder().addAllEquip(equipList).build();
MessageUtil.sendMessage(iSession,1,MessageTypeProto.MessageType.GET_ALL_EQUIP_RESPONSE_VALUE,build,true);
}
public static class Instance {
@ -178,24 +189,37 @@ public class HeroLogic {
User user = UserManager.getUser(session.getUid());
List<CommonProto.TeamPosInfo> teamPosInfoList = new ArrayList<>();
TeamPosManager teamPosManager = user.getTeamPosManager();
Map<Integer, List<String>> teamPosForHero = teamPosManager.getTeamPosForHero();
Map<Integer, List<TeamPosHeroInfo>> teamPosForHero = teamPosManager.getTeamPosForHero();
Map<Integer, String> teamNames = teamPosManager.getTeamNames();
Map<Integer, List<Integer>> teamPosForPoken = teamPosManager.getTeamPosForPoken();
Map<Integer, List<TeamPosForPokenInfo>> teamPosForPoken = teamPosManager.getTeamPosForPoken();
for(Integer teamId:teamPosForHero.keySet()){
List<String> heroIds = teamPosForHero.get(teamId);
List<Integer> pokenIds = teamPosForPoken.get(teamId);
if(null == pokenIds){
pokenIds = new ArrayList<>(1);
List<TeamPosHeroInfo> teamPosHeroInfoList = teamPosForHero.get(teamId);
List<TeamPosForPokenInfo> teamPosForPokenInfos = teamPosForPoken.get(teamId);
if(null == teamPosForPokenInfos){
teamPosForPokenInfos = new ArrayList<>(1);
}
String teamName = teamNames.get(teamId);
if(StringUtil.isEmpty(teamName)){
teamName="";
}
List<CommonProto.TeamHeroInfo> teamHeroInfoList = new ArrayList<>();
for(TeamPosHeroInfo teamPosHeroInfo :teamPosHeroInfoList ){
teamHeroInfoList.add(
CommonProto.TeamHeroInfo.newBuilder().setPosition(teamPosHeroInfo.getPosition()).setHeroId(teamPosHeroInfo.getHeroId()).build()
);
}
List<CommonProto.TeamPokemonInfo> pokemonInfoList = new ArrayList<>();
for(TeamPosForPokenInfo teamPokemonInfo : teamPosForPokenInfos){
pokemonInfoList.add(
CommonProto.TeamPokemonInfo.newBuilder().setPokemonId(teamPokemonInfo.getPokenId()).setPosition(teamPokemonInfo.getPosition()).build()
);
}
teamPosInfoList.add(
CommonProto.TeamPosInfo.newBuilder()
.addAllHeroIds(heroIds)
.addAllPokemonIds(pokenIds)
.addAllTeamHeroInfos(teamHeroInfoList)
.addAllTeamPokemonInfos(pokemonInfoList)
.setTeamName(teamName)
.setTeamId(teamId)
.build()
);
}
@ -203,9 +227,9 @@ public class HeroLogic {
MessageUtil.sendMessage(session,1,MessageTypeProto.MessageType.GET_TEAMPOS_INFO_RESPONSE_VALUE,build,true);
}
public void saveTeamPos(ISession iSession,int teamId,List<String> heroIds ,List<Integer> pokemonoIds) throws Exception {
public void saveTeamPos(ISession iSession, int teamId, List<CommonProto.TeamHeroInfo> heroIds , List<CommonProto.TeamPokemonInfo> pokemonoIds) throws Exception {
User user = UserManager.getUser(iSession.getUid());
String err = checkTeamPos(user, heroIds,pokemonoIds);
String err = checkTeamPos(user, teamId,heroIds,pokemonoIds);
if(!"".equals(err)){
MessageUtil.sendErrorResponse(iSession,0,MessageTypeProto.MessageType.TEAM_POS_SAVE_RESPONSE_VALUE,err);
return;
@ -214,31 +238,43 @@ public class HeroLogic {
MessageUtil.sendMessage(iSession,1,MessageTypeProto.MessageType.TEAM_POS_SAVE_RESPONSE_VALUE,null,true);
}
public String checkTeamPos(User user,List<String> heroIds,List<Integer> pokemonoIds ){
public String checkTeamPos(User user, int teamId,List<CommonProto.TeamHeroInfo> heroIds, List<CommonProto.TeamPokemonInfo> pokemonoIds ){
if(heroIds ==null || heroIds.isEmpty()){
return "队伍信息错误";
}
Set<String> cacheHeroIds = new HashSet<>();
Collection<List<String>> values = user.getTeamPosManager().getTeamPosForHero().values();
for(String heroId : heroIds){
Set<String> alreadyHeroIds = new HashSet<>();
Map<Integer, List<TeamPosHeroInfo>> teamPosForHero = user.getTeamPosManager().getTeamPosForHero();
for(Integer teamIdTmp : teamPosForHero.keySet()){
if(teamIdTmp == teamId){
continue;
}
List<TeamPosHeroInfo> teamPosHeroInfoList = teamPosForHero.get(teamIdTmp);
for(TeamPosHeroInfo teamPosHeroInfo : teamPosHeroInfoList){
alreadyHeroIds.add(teamPosHeroInfo.getHeroId());
}
}
for(CommonProto.TeamHeroInfo teamHeroInfo: heroIds){
String heroId = teamHeroInfo.getHeroId();
if(user.getHeroManager().getHero(heroId) == null) {
// 卡牌不存在
return "card not exists";
}
// 卡牌重复
// 卡牌重复 卡牌已上阵
if(cacheHeroIds.contains(heroId)){
return "card repeated";
}
// 卡牌已上阵
if(values.contains(heroId)){
return "card has already in teampos";
if(alreadyHeroIds.contains(heroId)){
return "card repeated";
}
cacheHeroIds.add(heroId);
}
Map<Integer, Pokemon> pokemonMap = user.getPokemonManager().getPokemonMap();
for(Integer pokemonoId : pokemonoIds){
if( !pokemonMap.containsKey(pokemonoId)){
for(CommonProto.TeamPokemonInfo pokemonInfo : pokemonoIds){
int pokemonId = pokemonInfo.getPokemonId();
if( !pokemonMap.containsKey(pokemonId)){
return "pokemono not exists";
}
}
@ -602,8 +638,10 @@ public class HeroLogic {
int equipIdTid = equip.getEquipId();
SEquipConfig sEquipConfig = SEquipConfig.getsEquipConfigById(equipIdTid);
int position = sEquipConfig.getPosition();
Map<Integer, String> equipByPositionMap = hero.getEquipByPositionMap();
if( equipByPositionMap!=null && equipByPositionMap.get(position)!= null){
int professionLimit = sEquipConfig.getProfessionLimit();
SCHero scHero = SCHero.getsCHero().get(hero.getTemplateId());
if(professionLimit!=0 && scHero.getProfession()!= professionLimit){
MessageUtil.sendErrorResponse(session,0,MessageTypeProto.MessageType.EQUIP_WEAR_REQUEST_VALUE,"");
return;
}

View File

@ -5,6 +5,7 @@ import com.ljsd.jieling.protocols.CommonProto;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class CBean2Proto {
@ -75,18 +76,26 @@ public class CBean2Proto {
}
private static List<String> getHeroEquip(List<Equip> equipList) {
List<String> equips = new ArrayList<>();
return equips;
}
public static CommonProto.Equip getEquipProto(Equip equip){
Map<Integer, Integer> propertyValueByIdMap = equip.getPropertyValueByIdMap();
Map<Integer, Integer> secondValueByIdMap = equip.getSecondValueByIdMap();
CommonProto.Equip equipProto =CommonProto.Equip.newBuilder()
.setEquipId(equip.getEquipId())
.setId(equip.getId())
.setMainAttribute(parseFromMap(propertyValueByIdMap).get(0))
.addAllSecondAttribute(parseFromMap(secondValueByIdMap))
.build();
return equipProto;
}
private static List<CommonProto.SpecialEffects> parseFromMap(Map<Integer,Integer> propertyValueByIdMap){
List<CommonProto.SpecialEffects> result = new ArrayList<>();
for(Integer propertyId:propertyValueByIdMap.keySet()){
result.add(CommonProto.SpecialEffects.newBuilder().setPropertyId(propertyId).setPropertyValue(propertyValueByIdMap.get(propertyId)).build());
}
return result;
}
}