道具消耗
parent
57f73449d8
commit
7ab8e61bbc
|
@ -7,6 +7,7 @@ public interface GlobalItemType {
|
|||
int SUCCESSIVELY_RANDOM = 2; // 依次随机
|
||||
|
||||
// 物品类型
|
||||
int GEM = 1; // 钻石Id(充值获得)
|
||||
int ITEM = 10; //道具
|
||||
int CARD = 11; // 卡牌
|
||||
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package com.ljsd.jieling.handler;
|
||||
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.protocols.CommonProto;
|
||||
import com.ljsd.jieling.protocols.MessageTypeProto;
|
||||
import com.ljsd.jieling.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
|
@ -34,27 +36,8 @@ public class GetAllItemHandler extends BaseHandler {
|
|||
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},messageNum={},messageStr={}",
|
||||
userId, token,msgId,msgIndex,getItemInfoRequest.getNum(),getItemInfoRequest.getStr());
|
||||
|
||||
List<CommonProto.Item> itemList = new ArrayList<>();
|
||||
CommonProto.Item item1 = CommonProto.Item.newBuilder()
|
||||
.setItemId(1)
|
||||
.setItemNum(111)
|
||||
.build();
|
||||
CommonProto.Item item2 = CommonProto.Item.newBuilder()
|
||||
.setItemId(2)
|
||||
.setItemNum(222)
|
||||
.build();
|
||||
CommonProto.Item item3 = CommonProto.Item.newBuilder()
|
||||
.setItemId(3)
|
||||
.setItemNum(333)
|
||||
.build();
|
||||
|
||||
|
||||
itemList.add(item1);
|
||||
itemList.add(item2);
|
||||
itemList.add(item3);
|
||||
|
||||
// User user = UserManager.getUserForLogin(userId);
|
||||
// List<CommonProto.Item> itemList = ItemUtil.getAllItem(user);
|
||||
User user = UserManager.getUserForLogin(userId);
|
||||
List<CommonProto.Item> itemList = ItemUtil.getAllItem(user);
|
||||
PlayerInfoProto.GetItemInfoResponse getItemInfoResponse = PlayerInfoProto.GetItemInfoResponse.newBuilder()
|
||||
.addAllItemlist(itemList)
|
||||
.build();
|
||||
|
|
|
@ -200,4 +200,73 @@ public class ItemUtil {
|
|||
heroList.add(CBean2Proto.getHero(hero));
|
||||
}
|
||||
|
||||
|
||||
public static boolean itemCost(User user,int[][] costItems) throws Exception {
|
||||
|
||||
Map<Integer, Integer> itemMap = new HashMap<>();
|
||||
Map<Integer, Integer> moneyMap = new HashMap<>();
|
||||
selectCost(costItems,itemMap,moneyMap);
|
||||
boolean result = checkCost(user, itemMap, moneyMap);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
useItem(user, itemMap);
|
||||
useMoney(user, moneyMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void useMoney(User user, Map<Integer, Integer> moneyMap) throws Exception {
|
||||
for (Map.Entry<Integer, Integer> entry : moneyMap.entrySet()) {
|
||||
int itemId = entry.getKey();
|
||||
int itemNum = entry.getValue();
|
||||
if (itemId==GlobalItemType.GEM){
|
||||
user.getPlayerInfoManager().setGem(user.getPlayerInfoManager().getGem() - itemNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkCost(User user, Map<Integer, Integer> itemMap, Map<Integer, Integer> moneyMap) {
|
||||
if (itemMap != null) {
|
||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||
Item item = user.getItemManager().getItem(entry.getKey());
|
||||
if (item == null || item.getItemNum() < entry.getValue()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (moneyMap != null) {
|
||||
for (Map.Entry<Integer, Integer> entry : moneyMap.entrySet()) {
|
||||
int count = 0;
|
||||
if (entry.getKey() == GlobalItemType.GEM) {
|
||||
count = user.getPlayerInfoManager().getGem();
|
||||
}
|
||||
if (count < entry.getValue()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private static void selectCost(int[][] costItems, Map<Integer, Integer> itemMap, Map<Integer, Integer> moneyMap) {
|
||||
for (int[] costItem : costItems){
|
||||
int itemId = costItem[0];
|
||||
int itemNum = costItem[1];
|
||||
SItem sItem = SItem.getsItemMap().get(itemId);
|
||||
switch (sItem.getItemType()) {
|
||||
case GlobalItemType.GEM:
|
||||
putcountMap(itemId,itemNum,moneyMap);
|
||||
break;
|
||||
case GlobalItemType.ITEM:
|
||||
putcountMap(itemId,itemNum,itemMap);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ public class ExcelUtils {
|
|||
int rownum = sheet.getLastRowNum();
|
||||
FileWriter fw = new FileWriter(path + sheetName + ".txt");
|
||||
PrintWriter out = new PrintWriter(fw);
|
||||
for (int i = 0; i < rownum; i++) {
|
||||
for (int i = 0; i <= rownum; i++) {
|
||||
if (i == 2 || i == 3 || i == 4 ||i == 5||i == 6){
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue