GM添加卡牌
parent
49b9d9c4f2
commit
deec982cb9
|
|
@ -2,4 +2,5 @@ package com.ljsd.jieling.globals;
|
|||
|
||||
public interface GlobalGm {
|
||||
int ADD_ITEM = 0;//添加道具
|
||||
int ADD_CARD = 1; //添加卡牌
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,37 +39,22 @@ public class DrawHeroHandler extends BaseHandler {
|
|||
CommonProto.Hero hero1 = CommonProto.Hero.newBuilder()
|
||||
.setId("aaa")
|
||||
.setHeroId(1)
|
||||
.setAttack(2)
|
||||
.setStar(2)
|
||||
.setLevel(1)
|
||||
.setHp(1000)
|
||||
.setMDefence(2000)
|
||||
.setPDefence(3000)
|
||||
.setSpeed(4000)
|
||||
.build();
|
||||
|
||||
CommonProto.Hero hero2 = CommonProto.Hero.newBuilder()
|
||||
.setId("bbb")
|
||||
.setHeroId(2)
|
||||
.setAttack(2)
|
||||
.setStar(2)
|
||||
.setLevel(1)
|
||||
.setHp(1000)
|
||||
.setMDefence(2000)
|
||||
.setPDefence(3000)
|
||||
.setSpeed(4000)
|
||||
.build();
|
||||
|
||||
CommonProto.Hero hero3 = CommonProto.Hero.newBuilder()
|
||||
.setId("ccc")
|
||||
.setHeroId(3)
|
||||
.setAttack(2)
|
||||
.setStar(2)
|
||||
.setLevel(1)
|
||||
.setHp(1000)
|
||||
.setMDefence(2000)
|
||||
.setPDefence(3000)
|
||||
.setSpeed(4000)
|
||||
.build();
|
||||
|
||||
heroList.add(hero1);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.ljsd.jieling.network.session.ISession;
|
|||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -34,14 +35,30 @@ public class GMRequestHandler extends BaseHandler{
|
|||
}
|
||||
String[] commandArray = command.split("#");
|
||||
int uid = Integer.parseInt(commandArray[0]);
|
||||
int gmCommandType = Integer.parseInt(commandArray[1]);// type 0:添加道具
|
||||
int gmCommandType = Integer.parseInt(commandArray[1]);// type 0:添加道具 1:卡牌
|
||||
int prarm1 = 0, prarm2 = 0;
|
||||
User cUser = UserManager.getUser(uid);
|
||||
switch (gmCommandType){
|
||||
case GlobalGm.ADD_ITEM:
|
||||
giveItem(cUser,prarm1,prarm2);
|
||||
break;
|
||||
case GlobalGm.ADD_CARD:
|
||||
giveHero(cUser,prarm1,prarm2);
|
||||
break;
|
||||
}
|
||||
try {
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GM_RESPONSE_VALUE, null, true);
|
||||
LOGGER.info("back to client!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void giveHero(User cUser, int cardId, int cardNum) throws Exception {
|
||||
CommonProto.Drop.Builder dropBuilder = CommonProto.Drop.newBuilder();
|
||||
Map<Integer,Integer> cardMap = new ConcurrentHashMap<>();
|
||||
cardMap.put(cardId,cardNum);
|
||||
ItemUtil.addCard(cUser,cardMap,dropBuilder);
|
||||
}
|
||||
|
||||
private void giveItem(User cUser,int itemId,int itemNum) throws Exception {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,9 @@ public class ItemUtil {
|
|||
ItemManager itemManager = user.getItemManager();
|
||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||
SItem sItem = SItem.getsItemMap().get(entry.getKey());
|
||||
if (sItem == null){
|
||||
continue;
|
||||
}
|
||||
Item item = itemManager.getItem(entry.getKey());
|
||||
if (item == null){
|
||||
item = itemManager.newItem(entry.getKey(), entry.getValue());
|
||||
|
|
@ -191,6 +194,7 @@ public class ItemUtil {
|
|||
addCard(user, entry.getKey(),heroList);
|
||||
}
|
||||
}
|
||||
dropBuilder.addAllHero(heroList);
|
||||
}
|
||||
|
||||
public static void addCard(User user,int cardId,List<CommonProto.Hero> heroList) throws Exception {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package network.client;
|
|||
|
||||
import com.google.protobuf.*;
|
||||
import com.ljsd.jieling.netty.cocdex.Tea;
|
||||
import com.ljsd.jieling.protocols.GMCommandProto;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.HeroInfoProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
|
|
@ -44,6 +44,7 @@ public class NettyClient {
|
|||
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
|
||||
handler.sendRequest_jieling(makeFinalMessage(getHero(), MessageTypeProto.MessageType.GET_HEROINFO_REQUEST_VALUE));
|
||||
handler.sendRequest_jieling(makeFinalMessage(getRandomHero(), MessageTypeProto.MessageType.HERO_RAND_REQQUEST_VALUE));
|
||||
handler.sendRequest_jieling(makeFinalMessage(gmRequest(), MessageTypeProto.MessageType.GM_REQUEST_VALUE));
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +70,8 @@ public class NettyClient {
|
|||
return finalData;
|
||||
}
|
||||
|
||||
public static GMCommandProto.GMCommand gmRequest(){
|
||||
return GMCommandProto.GMCommand.newBuilder().setCommand("10000001#0#1#100").build();
|
||||
public static CommonProto.GMCommand gmRequest(){
|
||||
return CommonProto.GMCommand.newBuilder().setCommand("10000001#0#1#100").build();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue