467 lines
10 KiB
C#
467 lines
10 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-11-03
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "MovesShop" company="Kunpo"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace G
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 招式商店
|
|||
|
/// </summary>
|
|||
|
public class MovesShop : MonoBehaviour
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private class MovesPackageItemInfo
|
|||
|
{
|
|||
|
public int id;
|
|||
|
public int parentId;
|
|||
|
public int weight;
|
|||
|
public int tmpWeight;
|
|||
|
}
|
|||
|
|
|||
|
#region Field
|
|||
|
|
|||
|
public const int MAX_CARD_COUNT = 3;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int movesPoint
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public int totalMovesPoint
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
}
|
|||
|
|
|||
|
public int refreshCount
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
} = 0;
|
|||
|
|
|||
|
public int refreshCountMax
|
|||
|
{
|
|||
|
get;
|
|||
|
private set;
|
|||
|
} = 0;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 显示的三张卡
|
|||
|
/// </summary>
|
|||
|
public readonly List<int> showMoves = new List<int>();
|
|||
|
/// <summary>
|
|||
|
/// 已购买
|
|||
|
/// </summary>
|
|||
|
public readonly HashSet<int> studiedMoves = new HashSet<int>();
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private readonly List<int> _lastStudiedMoves = new List<int>();
|
|||
|
|
|||
|
private int _movesPackageId;
|
|||
|
private int _movesPackageType = 0;
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
private readonly Dictionary<int, MovesPackageItemInfo> _movesPackage = new Dictionary<int, MovesPackageItemInfo>();
|
|||
|
|
|||
|
private Callback2 _studyCallback;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Method
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="point"></param>
|
|||
|
public void AddMovesPoint(int point)
|
|||
|
{
|
|||
|
movesPoint += point;
|
|||
|
totalMovesPoint += point;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void ResetMovesPoint()
|
|||
|
{
|
|||
|
movesPoint = 0;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="moves"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private bool CheckMoves(ItemMoves moves)
|
|||
|
{
|
|||
|
return moves.unlock == 0 || MissionProxy.Instance.IsCompletedMission(moves.unlock);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 技能卡包
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
public void SetMovesPackage(int id, bool auto, Callback2 callback)
|
|||
|
{
|
|||
|
_studyCallback = callback;
|
|||
|
|
|||
|
_movesPackageId = id;
|
|||
|
_movesPackageType = 0;
|
|||
|
_movesPackage.Clear();
|
|||
|
|
|||
|
if (_movesPackageId > 0)
|
|||
|
{
|
|||
|
var package = ItemProxy.Instance.GetStaticItem<ItemMovesPackage>(_movesPackageId);
|
|||
|
_movesPackageType = package.type;
|
|||
|
for (int i = 0; i < package.skillCards.Length; i += 2)
|
|||
|
{
|
|||
|
int pid = package.skillCards[i];
|
|||
|
var pw = package.skillCards[i + 1];
|
|||
|
|
|||
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(package.skillCards[i]);
|
|||
|
if (CheckMoves(movesItem))
|
|||
|
_movesPackage.Add(pid, new MovesPackageItemInfo
|
|||
|
{
|
|||
|
id = pid,
|
|||
|
parentId = movesItem.parent,
|
|||
|
weight = pw != 0 ? pw : movesItem.weight,
|
|||
|
});
|
|||
|
}
|
|||
|
movesPoint = 1;
|
|||
|
RefreshMoves(MAX_CARD_COUNT);
|
|||
|
GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, auto ? "auto" : "", "skill_shop");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 多选技能
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <param name="count"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public void SetMultiMovesPackage(int id, int count, Callback2 callback)
|
|||
|
{
|
|||
|
_studyCallback = callback;
|
|||
|
|
|||
|
_movesPackageId = id;
|
|||
|
_movesPackageType = 0;
|
|||
|
_movesPackage.Clear();
|
|||
|
|
|||
|
if (_movesPackageId > 0)
|
|||
|
{
|
|||
|
var package = ItemProxy.Instance.GetStaticItem<ItemMovesPackage>(_movesPackageId);
|
|||
|
_movesPackageType = package.type;
|
|||
|
for (int i = 0; i < package.skillCards.Length; i += 2)
|
|||
|
{
|
|||
|
int pid = package.skillCards[i];
|
|||
|
var pw = package.skillCards[i + 1];
|
|||
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(package.skillCards[i]);
|
|||
|
//if (true || CheckMoves(movesItem))
|
|||
|
_movesPackage.Add(pid, new MovesPackageItemInfo
|
|||
|
{
|
|||
|
id = pid,
|
|||
|
parentId = movesItem.parent,
|
|||
|
weight = pw != 0 ? pw : movesItem.weight,
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
movesPoint = count;
|
|||
|
RefreshMultiMoves(count + 3);
|
|||
|
GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, false, "skill_shop");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public bool RefreshMovesShop(bool free)
|
|||
|
{
|
|||
|
if (refreshCount > 0 || free)
|
|||
|
{
|
|||
|
#if UNITY_EDITOR || DEBUG_MY
|
|||
|
#else
|
|||
|
if (!free)
|
|||
|
this.refreshCount--;
|
|||
|
#endif
|
|||
|
RefreshMoves(MAX_CARD_COUNT);
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设置可学
|
|||
|
/// </summary>
|
|||
|
private void RefreshMoves(int count)
|
|||
|
{
|
|||
|
showMoves.Clear();
|
|||
|
|
|||
|
if (_movesPackageId > 0)
|
|||
|
{
|
|||
|
if (_movesPackageType == 0)
|
|||
|
{
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (studiedMoves.Contains(item.id))
|
|||
|
{
|
|||
|
item.weight = 0;
|
|||
|
item.tmpWeight = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
item.tmpWeight = item.parentId == 0 || studiedMoves.Contains(item.parentId) ? item.weight : 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; i < count; i++)
|
|||
|
{
|
|||
|
int totalW = 0;
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
totalW += item.tmpWeight;
|
|||
|
}
|
|||
|
|
|||
|
var currW = Random.Range(0, totalW);
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (item.tmpWeight <= 0)
|
|||
|
continue;
|
|||
|
currW -= item.tmpWeight;
|
|||
|
if (currW < 0)
|
|||
|
{
|
|||
|
item.tmpWeight = 0;
|
|||
|
showMoves.Add(item.id);
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if (_movesPackageType == 1)
|
|||
|
{
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (showMoves.Count < count)
|
|||
|
showMoves.Add(item.id);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设置可学
|
|||
|
/// </summary>
|
|||
|
private void RefreshMultiMoves(int count)
|
|||
|
{
|
|||
|
showMoves.Clear();
|
|||
|
if (_movesPackageId <= 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
count = Mathf.Min(count, _movesPackage.Count);
|
|||
|
|
|||
|
if (_movesPackageType == 0)
|
|||
|
{
|
|||
|
Comp:
|
|||
|
if (showMoves.Count == 0)
|
|||
|
{
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
item.tmpWeight = item.parentId == 0 ? item.weight : 0;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (item.parentId > 0)
|
|||
|
item.tmpWeight = showMoves.Contains(item.parentId) ? item.weight : 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (int i = showMoves.Count; i < count; i++)
|
|||
|
{
|
|||
|
int totalW = 0;
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (item.tmpWeight > 0)
|
|||
|
totalW += item.tmpWeight;
|
|||
|
}
|
|||
|
|
|||
|
var currW = Random.Range(0, totalW);
|
|||
|
foreach (var item in _movesPackage.Values)
|
|||
|
{
|
|||
|
if (item.tmpWeight <= 0)
|
|||
|
continue;
|
|||
|
currW -= item.tmpWeight;
|
|||
|
if (currW < 0)
|
|||
|
{
|
|||
|
if (item.parentId > 0 && !showMoves.Contains(item.parentId))
|
|||
|
{
|
|||
|
var parent = _movesPackage[item.parentId];
|
|||
|
parent.tmpWeight = 0;
|
|||
|
showMoves.Add(parent.id);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
item.tmpWeight = 0;
|
|||
|
showMoves.Add(item.id);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (showMoves.Count < count)
|
|||
|
{
|
|||
|
goto Comp;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
public bool StudyMoves(int id, bool free = false)
|
|||
|
{
|
|||
|
if (id > 0)
|
|||
|
{
|
|||
|
var skillCardItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(id);
|
|||
|
studiedMoves.Add(id);
|
|||
|
_lastStudiedMoves.Add(id);
|
|||
|
//if (movesPoint >= skillCardItem.price)
|
|||
|
//{
|
|||
|
// movesPoint -= skillCardItem.price;
|
|||
|
// studiedMoves.Add(id);
|
|||
|
// _lastStudiedMoves.Add(id);
|
|||
|
//}
|
|||
|
KStatistics.Instance.ReportEvent("study_skill", $"{{\"ectype_name\":\"{skillCardItem.name}\"}}");
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="movesIds"></param>
|
|||
|
/// <param name="free"></param>
|
|||
|
public void StudyMoves(IEnumerable<int> movesIds, bool free = false)
|
|||
|
{
|
|||
|
foreach (var id in movesIds)
|
|||
|
if (id > 0)
|
|||
|
{
|
|||
|
studiedMoves.Add(id);
|
|||
|
_lastStudiedMoves.Add(id);
|
|||
|
//var skillCardItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(id);
|
|||
|
//if (movesPoint >= skillCardItem.price)
|
|||
|
//{
|
|||
|
// movesPoint -= skillCardItem.price;
|
|||
|
// studiedMoves.Add(id);
|
|||
|
// _lastStudiedMoves.Add(id);
|
|||
|
//}
|
|||
|
}
|
|||
|
KStatistics.Instance.ReportEvent("study_skill", $"{{\"ectype_name\":\"all\"}}");
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 学习指定 技能
|
|||
|
/// </summary>
|
|||
|
/// <param name="movesIds"></param>
|
|||
|
public void StudyMoves(IEnumerable<int> movesIds)
|
|||
|
{
|
|||
|
foreach (var id in movesIds)
|
|||
|
if (id > 0)
|
|||
|
{
|
|||
|
studiedMoves.Add(id);
|
|||
|
_lastStudiedMoves.Add(id);
|
|||
|
}
|
|||
|
ApplyLastStudiedMoves();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="free"></param>
|
|||
|
public void StudyAllMoves(bool free = false)
|
|||
|
{
|
|||
|
StudyMoves(showMoves, free);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
public void ApplyLastStudiedMoves(bool doubleValue = false)
|
|||
|
{
|
|||
|
//先学前置技能
|
|||
|
for (int i = 0; i < _lastStudiedMoves.Count; i++)
|
|||
|
{
|
|||
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(_lastStudiedMoves[i]);
|
|||
|
if (movesItem != null && movesItem.parent == 0)
|
|||
|
{
|
|||
|
EntityMainPlayer.Instance.AddMoves(movesItem.id, doubleValue);
|
|||
|
}
|
|||
|
}
|
|||
|
//再学子技能
|
|||
|
for (int i = 0; i < _lastStudiedMoves.Count; i++)
|
|||
|
{
|
|||
|
var movesItem = ItemProxy.Instance.GetStaticItem<ItemMoves>(_lastStudiedMoves[i]);
|
|||
|
if (movesItem != null && movesItem.parent > 0)
|
|||
|
{
|
|||
|
EntityMainPlayer.Instance.AddMoves(movesItem.id, doubleValue);
|
|||
|
}
|
|||
|
}
|
|||
|
_lastStudiedMoves.Clear();
|
|||
|
|
|||
|
if (_studyCallback != null)
|
|||
|
{
|
|||
|
_studyCallback(0, "");
|
|||
|
_studyCallback = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Unity
|
|||
|
|
|||
|
private static MovesShop _Instance;
|
|||
|
public static MovesShop Instance
|
|||
|
{
|
|||
|
get { return _Instance; }
|
|||
|
}
|
|||
|
|
|||
|
// Use this for initialization
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_Instance = this;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|