Files
JJBB/Assets/Project/Script/GUI/Shop/SysShopController.cs
2024-08-23 15:49:34 +08:00

535 lines
20 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using GCGame;
using System.Collections.Generic;
using GCGame.Table;
using Games.Item;
using Games.LogicObj;
using Module.Log;
using Games.Mission;
public class SysShopController : UIControllerBase<SysShopController>
{
public enum ItemNeedSys
{
GuildTransport,
LoopMission,
}
#region static call
public static int _SelectedItem = -1;
private static bool NeedShowLevel = false;
public static void ShowShopStr(string shopIDStr)
{
int shopId = int.Parse(shopIDStr);
ShowShop(shopId);
}
public static void ShowShop(int shopID, bool needShowLv = false)
{
//if (SysShopController.Instance())
//{
// SysShopController.Instance().InitShop(shopID);
//}
//else
{
NeedShowLevel = needShowLv;
List<object> initParams = new List<object>();
initParams.Add(shopID);
UIManager.ShowUI(UIInfo.SysShop, SysShopController.ShowUIOver, initParams);
}
}
//判断是否有寻物任务在身上
public static Dictionary<string, int> _LackItemSysCountDic = new Dictionary<string, int>(); //SysID表示系统ID 就是那个系统需求的,可以随便设置,但不要重复
public static void AddNeed(int SysID,int ItemID,int ItemNum)
{
string keyID = string.Format("s{0}s_{1}", SysID, ItemID);
_LackItemSysCountDic[keyID] = ItemNum;
}
public static int ItemNeedCount(int ItemID)
{
int count = 0;
List<string> keys = new List<string>(_LackItemSysCountDic.Keys);
for (int i = 0; i < keys.Count; i++)
{
if(keys[i].Contains(ItemID.ToString()))
{
count += _LackItemSysCountDic[keys[i]];
}
}
GameItemContainer Container = GameManager.gameManager.PlayerDataPool.GetItemContainer(GameItemContainer.Type.TYPE_BACKPACK);
if (Container == null)
{
return 0;
}
count = count - Container.GetItemCountByDataId(ItemID);
return count < 0 ? 0 : count;
}
public static void DelNeed(int SysID, int ItemID,bool _all = false)
{
string keySysID = string.Format("s{0}s_", SysID);
string keyID = string.Format("s{0}s_{1}", SysID, ItemID);
if (_all)
{
List<string> keys = new List<string>(_LackItemSysCountDic.Keys);
for(int i=0;i<keys.Count;i++)
{
if(keys[i].Contains(keySysID))
{
_LackItemSysCountDic.Remove(keys[i]);
}
}
return;
}
if (_LackItemSysCountDic.ContainsKey(keyID))
_LackItemSysCountDic.Remove(keyID);
}
public static void ShowShopForItem(int shopID, int itemID)
{
_SelectedItem = itemID;
//if (SysShopController.Instance())
//{
// SysShopController.Instance().InitShop(shopID);
//}
//else
{
List<object> initParams = new List<object>();
initParams.Add(shopID);
UIManager.ShowUI(UIInfo.SysShop, SysShopController.ShowUIOver, initParams);
}
}
static void ShowUIOver(bool bSuccess, object param)
{
if (bSuccess)
{
List<object> initParams = param as List<object>;
if (SysShopController.Instance() != null && initParams != null && initParams.Count > 0)
{
SysShopController.Instance().InitShop((int)initParams[0]);
}
}
}
#endregion
public Text _ShopName;
public SysShopPage _ShopPage;
public GameObject _SwitchBtn;
private int _ShopID;
void Awake()
{
SetInstance(this);
}
void OnDestory()
{
SetInstance(null);
}
public void InitShop(int shopID, bool _IsPropMoney = false)
{
//_SwitchBtn.gameObject.SetActive(!_IsPropMoney);
_ShopID = shopID;
int selectedItem = _SelectedItem;
_SelectedItem = -1;
var m_curShopTable = TableManager.GetSystemShopByID(_ShopID, 0);
_ShopName.text = m_curShopTable.Name;
bool isBuyLimit = false;
List<SysShopPageItem.ShopItemInfo> shopItems = new List<SysShopPageItem.ShopItemInfo>();
for (int i = 0, count = m_curShopTable.getPidCount(); i < count; i++)
{
SysShopPageItem.ShopItemInfo shopItemInfo = new SysShopPageItem.ShopItemInfo();
Tab_CommonItem curTabItem = TableManager.GetCommonItemByID(m_curShopTable.GetPidbyIndex(i), 0);
if (null != curTabItem)
{
shopItemInfo.MoneyType = (MONEYTYPE)m_curShopTable.GetMoneySubTypebyIndex(i);
shopItemInfo.TabItem = curTabItem;
shopItemInfo.Price = m_curShopTable.GetPricebyIndex(i);
shopItemInfo.GroupCount = m_curShopTable.GetNumPerGroupbyIndex(i);
shopItemInfo.ItemIdxInShop = i;
shopItemInfo.LimitID = m_curShopTable.GetLimitIdbyIndex(i);
shopItemInfo.LimitCount = 99;
isBuyLimit |= (shopItemInfo.LimitID != -1);
shopItemInfo.needShowLv = NeedShowLevel;
shopItems.Add(shopItemInfo);
}
//else
//{
// LogModule.DebugLog("systemshop:can not find cur item in item table, item id:" + m_curShopTable.GetPidbyIndex(i));
//}
}
if (isBuyLimit)
{
CG_REQ_SHOP_ITEM_LIMIT_LIST packet = (CG_REQ_SHOP_ITEM_LIMIT_LIST)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(shopID);
packet.SendPacket();
}
if (shopItems.Count > 0)
{
if(IsLootItemMission())
{
SetMyInNeedItemIconInfo(shopItems);
}
CheckItemNeed(shopItems);
// 必须先判断是否需要排序使用List.sort系统可能会调用不稳定的排序。除非重新写个稳定的排序
bool needSort = false;
for(int i = 0; i < shopItems.Count; ++i)
{
if(shopItems[i].isNeed > 0)
{
needSort = true;
break;
}
}
if (needSort == true)
{
shopItems.Sort(SortMyItemList);
}
//int i = 1;
_ShopPage.InitShop(shopItems[0].MoneyType, BuyItemCallBack);
List<SysShopPageItem.ShopItemInfo> selectedItems = new List<SysShopPageItem.ShopItemInfo>();
if (selectedItem > 0)
{
for (int i = 0; i < shopItems.Count; ++i)
{
if (shopItems[i].TabItem.Id == selectedItem)
{
selectedItems.Add(shopItems[i]);
}
}
}
_ShopPage.SetShopItems(shopItems, selectedItems);
}
}
bool IsLootItemMission()
{
if(GameManager.gameManager.MissionManager.MissionList.m_aMission.Count <= 0)
{
return false;
}
foreach (var m_Mission in GameManager.gameManager.MissionManager.MissionList.m_aMission)
{
Tab_MissionBase missionBase = TableManager.GetMissionBaseByID(m_Mission.Value.m_nMissionID, 0);
if(missionBase != null)
{
Tab_MissionLogic missionLogic = TableManager.GetMissionLogicByID(missionBase.LogicID, 0);
if(missionLogic != null)
{
for(int index = 0; index < missionLogic.getLogicTypeCount(); index++)
{
if(missionLogic.GetLogicTypebyIndex(index) == (int)TableType.Table_LootItem
&& GameManager.gameManager.MissionManager.GetMissionState(m_Mission.Key) != (int)MissionState.Mission_Completed)
{
return true;
}
}
}
}
}
return false;
}
public void CheckItemNeed(List<SysShopPageItem.ShopItemInfo> m_ShopItems)
{
for(int i=0;i<m_ShopItems.Count;i++)
{
SysShopPageItem.ShopItemInfo shopItem = m_ShopItems[i];
shopItem.isNeed += ItemNeedCount(shopItem.TabItem.Id);
}
}
public void SetMyInNeedItemIconInfo(List<SysShopPageItem.ShopItemInfo> m_ShopItems)
{
List<GameItem> m_BackPackItemList = ItemTool.ItemFilter(GameManager.gameManager.PlayerDataPool.BackPack, 0); //过滤背包中所有物品 存储在ItemList中
GameItemContainer Container = GameManager.gameManager.PlayerDataPool.GetItemContainer(GameItemContainer.Type.TYPE_BACKPACK);
if(Container == null)
{
return;
}
GameManager.gameManager.PlayerDataPool._MissionLootItemNeedCountDic.Clear();
foreach (var m_Mission in GameManager.gameManager.MissionManager.MissionList.m_aMission)
{
if(GameManager.gameManager.MissionManager.GetMissionState(m_Mission.Key) == 2)//完成的任务1
{
continue;
}
Tab_MissionBase missionBase = TableManager.GetMissionBaseByID(m_Mission.Value.m_nMissionID, 0);
if (missionBase != null)
{
Tab_MissionLogic missionLogic = TableManager.GetMissionLogicByID(missionBase.LogicID, 0);
if (missionLogic != null)
{
for (int m_LogicIndex = 0; m_LogicIndex < missionLogic.getLogicTypeCount(); m_LogicIndex++)
{
//寻物任务
if (missionLogic.GetLogicTypebyIndex(m_LogicIndex) == (int)TableType.Table_LootItem)
{
Tab_MissionLootItem missionLootItem = TableManager.GetMissionLootItemByID(missionLogic.GetLogicIDbyIndex(m_LogicIndex), 0);
if (missionLootItem.SelectType == 0 || missionLootItem.SelectType == 1) //dataid
{
int m_NeedItemDataid = missionLootItem.DataID;
int m_NeedCount = missionLootItem.ItemCount;
if(GameManager.gameManager.PlayerDataPool._MissionLootItemNeedCountDic.ContainsKey(m_NeedItemDataid))
{
GameManager.gameManager.PlayerDataPool._MissionLootItemNeedCountDic[m_NeedItemDataid] += m_NeedCount;
}else
{
GameManager.gameManager.PlayerDataPool._MissionLootItemNeedCountDic.Add(m_NeedItemDataid, m_NeedCount);
}
if(Container.GetItemByDataID(m_NeedItemDataid) != null
&& Container.GetItemByDataID(m_NeedItemDataid).StackCount >= m_NeedCount) //背包存在
{
return;
}
foreach (var m_Item in m_ShopItems)
{
if (m_NeedItemDataid == m_Item.TabItem.Id)
{
m_Item.isNeed += m_NeedCount;
}
}
}
else if (missionLootItem.SelectType == 2)//索引MissionSortItem表
{
//判断SubClassId ClassId
Tab_MissionSortItem sortItem = TableManager.GetMissionSortItemByID(missionLootItem.DataID, 0);
if (sortItem != null)
{
int m_NeedClassId = sortItem.ItemClass;
int m_NeedSubClassId = sortItem.ItemSubClass;
int m_NeedQuality = sortItem.ItemQuality;
int m_ItemMinLevel = sortItem.ItemLevelBot;
int m_ItemMaxLevel = sortItem.ItemLevelTop;
//判断背包中有没有
for (int m_BackItemIndex = 0; m_BackItemIndex < m_BackPackItemList.Count; m_BackItemIndex++)
{
if ((m_NeedClassId == -1 || m_BackPackItemList[m_BackItemIndex].GetClass() == m_NeedClassId)
&& (m_NeedSubClassId == -1 || m_BackPackItemList[m_BackItemIndex].GetSubClass() == m_NeedSubClassId)
&& (m_NeedQuality == -1 || (int)m_BackPackItemList[m_BackItemIndex].GetQuality() <= m_NeedQuality)
&& (m_ItemMinLevel == -1 || (m_BackPackItemList[m_BackItemIndex].GetMinLevelRequire() >= m_ItemMinLevel && m_BackPackItemList[m_BackItemIndex].GetMinLevelRequire() <= m_ItemMaxLevel)))
{
return;
}
}
foreach (var m_ShopItem in m_ShopItems)
{
if ((m_NeedClassId == -1 || m_ShopItem.TabItem.ClassID == m_NeedClassId)
&& (m_NeedSubClassId == -1 || m_ShopItem.TabItem.SubClassID == m_NeedSubClassId)
&& (m_NeedQuality == -1 || m_ShopItem.TabItem.Quality <= m_NeedQuality)
&& (m_ItemMinLevel == -1 || (m_ShopItem.TabItem.MinLevelRequire >= m_ItemMinLevel && m_ShopItem.TabItem.MinLevelRequire <= m_ItemMaxLevel)))
{
m_ShopItem.isNeed += 1;
}
else
{
m_ShopItem.isNeed += 0;
}
}
}
}
}
}
}
}
}
}
public static int SortMyItemList(SysShopPageItem.ShopItemInfo m_ItemA, SysShopPageItem.ShopItemInfo m_ItemB)
{
if (m_ItemA.isNeed > 0 && m_ItemB.isNeed > 0)
{
return m_ItemA.TabItem.MinLevelRequire.CompareTo(m_ItemB.TabItem.MinLevelRequire);
}
else if (m_ItemA.isNeed > 0 && m_ItemB.isNeed <= 0)
{
return -1;
}
else if (m_ItemA.isNeed <= 0 && m_ItemB.isNeed > 0)
{
return 1;
}
return 0;
}
public static int m_TipSelDataID = -1;
// 卖物品 改成分解
public static void SellItem(int packet, List<GameItem> sellItemList)
{
if(sellItemList.Count == 1 && m_TipSelDataID!=-1 && m_TipSelDataID!=sellItemList[0].DataID)
{
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("{#46228}"));
m_TipSelDataID = -1;
return;
}
CG_DECOMPOSITION_EQUIP sendMsg = (CG_DECOMPOSITION_EQUIP)PacketDistributed.CreatePacket(MessageID.PACKET_CG_DECOMPOSITION_EQUIP);
for (int i = 0; i < sellItemList.Count; i++)
{
if (sellItemList[i] != null && sellItemList[i].IsValid())
{
sendMsg.AddEquipguid(sellItemList[i].Guid);
}
}
sendMsg.SendPacket();
/*
CG_SYSTEMSHOP_SELL sellPacket = (CG_SYSTEMSHOP_SELL)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_SELL);
sellPacket.SetPackage(packet);
for (int i = 0; i < sellItemList.Count; ++i)
{
SellItemInfo sellInfo = new SellItemInfo();
sellInfo.Guid = sellItemList[i].Guid;
sellInfo.Count = sellItemList[i].StackCount;
sellPacket.AddItemInfo(sellInfo);
}
sellPacket.SendPacket();
*/
}
public void BuyItemCallBack(SysShopPageItem.ShopItemInfo shopItemInfo, int count)
{
BuyItem(shopItemInfo.ItemIdxInShop, count);
}
// 购买物品
public void BuyItem(int itemIndex, int count)
{
int curItemIndex = itemIndex;
Tab_SystemShop sysShopTable = TableManager.GetSystemShopByID(_ShopID, 0);
if (null == sysShopTable)
{
LogModule.ErrorLog("cur sysshop id isn't exist! : id " + _ShopID.ToString());
return;
}
int pid = sysShopTable.GetPricebyIndex(curItemIndex);
if (pid < 0)
{
LogModule.ErrorLog("can not find cur item pid : itemID" + pid.ToString());
return;
}
var currencyType = (MONEYTYPE)sysShopTable.GetMoneySubTypebyIndex(0);
var mainType = sysShopTable.GetMoneyTypebyIndex(0);
if ((int)mainType == (int)CONSUM_TYPE.MONEY) //属性值
{
if (!JudgeMoneyLogic.IsMoneyEnough((MONEYTYPE)sysShopTable.GetMoneySubTypebyIndex(itemIndex), sysShopTable.GetPricebyIndex(itemIndex) * count))
{
return;
}
}else
{
//判断当前的属性值是否足够消费
if (GameManager.gameManager.PlayerDataPool.GetPropInt((PropID.PropertyID)currencyType) < sysShopTable.GetPricebyIndex(itemIndex) * count)
{
//积分不够
string tips = StrDictionary.GetClientDictionaryString("#{6102}", PropID.GetAttrName((PropID.PropertyID)currencyType));
GUIData.AddNotifyData(tips);
return;
}
}
CG_SYSTEMSHOP_BUY buyPacket = (CG_SYSTEMSHOP_BUY)PacketDistributed.CreatePacket(MessageID.PACKET_CG_SYSTEMSHOP_BUY);
buyPacket.SetBuyNum(count);
buyPacket.SetShopId(_ShopID);
buyPacket.SetMercIndex(curItemIndex);
buyPacket.SendPacket();
Debug.Log("CG_SYSTEMSHOP_BUY send packet:" + _ShopID + "," + curItemIndex +"," + count);
}
public void Close()
{
UIManager.CloseUI(UIInfo.SysShop);
}
public void UpdateLimitInfo()
{
CG_REQ_SHOP_ITEM_LIMIT_LIST packet = (CG_REQ_SHOP_ITEM_LIMIT_LIST)PacketDistributed.CreatePacket(MessageID.PACKET_CG_REQ_SHOP_ITEM_LIMIT_LIST);
packet.SetShopid(_ShopID);
packet.SendPacket();
}
public void InitShopItemLimit(GC_RET_SHOP_ITEM_LIMIT_LIST packet)
{
LogModule.DebugLog("InitShopItemLimit");
_ShopPage._ShopItemContainer.ForeachActiveItem<SysShopPageItem>((shopItem) =>
{
foreach (var itemLimit in packet.itemlimtlistList)
{
if (itemLimit.Itemindex == shopItem._ShopItemInfo.ItemIdxInShop)
{
shopItem.SetLimit(itemLimit.Buycount);
}
}
});
_ShopPage.RefreshSelected();
}
//public int GetPrivilegeVipLimitBuyCount()
//{
// var limitCount = 0;
// var vipLevel = GameManager.gameManager.PlayerDataPool.VipCost;
// Dictionary<int, Tab_PrivilegeFunction> funcDic = new Dictionary<int, Tab_PrivilegeFunction>();
// foreach (var info in TableManager.GetPrivilegeFunction().Values)
// {
// if (info.PrivilegeId == 8) //限购次数
// {
// funcDic.Add(info.PrivilegeVipType, info);
// }
// }
// foreach (var info in GameManager.gameManager.PlayerDataPool.PrivilegeTypeStateDic)
// {
// if (info.Value)
// {
// if (funcDic.ContainsKey(info.Key))
// {
// if (int.Parse(funcDic[info.Key].GetVipbyIndex(vipLevel)) > limitCount)
// limitCount = int.Parse(funcDic[info.Key].GetVipbyIndex(vipLevel));
// }
// }
// }
// return limitCount;
//}
}