//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, October 09, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
|
using System;
|
using System.Text.RegularExpressions;
|
|
namespace Snxxz.UI
|
{
|
|
public class Treasure
|
{
|
public int id { get; private set; }
|
|
public int stage { get; private set; }
|
|
public int exp { get; private set; }
|
|
public bool alreadyClickChallenge { get; set; }
|
|
TreasureState m_State = TreasureState.Locked;
|
public TreasureState state
|
{
|
get { return m_State; }
|
set { m_State = value; }
|
}
|
|
int m_Progress = 0;
|
public int progress
|
{
|
get { return m_Progress; }
|
set { m_Progress = value; }
|
}
|
|
public bool isChallengeDungeonAble
|
{
|
get
|
{
|
if (state != TreasureState.Collecting)
|
{
|
return false;
|
}
|
var config = TreasureConfig.Get(id);
|
return progress >= config.RequirementTotal;// && config.LastSuccID > 0;
|
}
|
}
|
|
public int skillId
|
{
|
get
|
{
|
var job = PlayerDatas.Instance.baseData.Job;
|
var stage = treasureStages.Find((x) =>
|
{
|
return x.unlockType == TreasureStageUnlock.Skill;
|
});
|
return stage != null ? stage.GetSkill(job) : 0;
|
}
|
}
|
|
public List<TreasureStage> treasureStages = new List<TreasureStage>();
|
|
public Treasure(int _id)
|
{
|
this.id = _id;
|
}
|
|
public void RefreshLevel(int stage, int exp, bool alreadyClickChallenge)
|
{
|
this.stage = stage;
|
this.exp = exp;
|
this.alreadyClickChallenge = alreadyClickChallenge;
|
}
|
|
public void AddTreasureStage(TreasureUpConfig config)
|
{
|
var _stage = new TreasureStage(config);
|
treasureStages.Add(_stage);
|
}
|
|
public int GetStageId(int _stageIndex)
|
{
|
foreach (var item in treasureStages)
|
{
|
if (item.stage == _stageIndex)
|
{
|
return item.id;
|
}
|
}
|
|
return 0;
|
}
|
|
public int IndexOfStage(int _stage)
|
{
|
if (treasureStages[0].unlockType == TreasureStageUnlock.None)
|
{
|
return Mathf.Max(_stage - 1, 0);
|
}
|
return _stage;
|
}
|
}
|
|
public class AchievementGroup
|
{
|
AchievementModel model { get { return ModelCenter.Instance.GetModel<AchievementModel>(); } }
|
public int group { get; private set; }
|
List<int> achievements = new List<int>();
|
|
public AchievementGroup(int _category)
|
{
|
group = _category;
|
}
|
|
public void AddAchievement(int _achievement)
|
{
|
if (!achievements.Contains(_achievement))
|
{
|
achievements.Add(_achievement);
|
}
|
}
|
|
public void Sort()
|
{
|
achievements.Sort(AchievementCompare);
|
}
|
|
public bool Contain(int _achievementId)
|
{
|
return achievements.Contains(_achievementId);
|
}
|
|
public bool IsAwardable()
|
{
|
var doingAchievement = GetDoingAchievement();
|
if (doingAchievement > 0)
|
{
|
Achievement achievement;
|
if (model.TryGetAchievement(doingAchievement, out achievement) && !achievement.completed)
|
{
|
return Achievement.IsReach(doingAchievement, achievement.progress);
|
}
|
}
|
return false;
|
}
|
|
public bool IsCompleted()
|
{
|
var achievementId = GetDoingAchievement();
|
Achievement doingAchievement;
|
if (model.TryGetAchievement(achievementId, out doingAchievement) && doingAchievement.completed)
|
{
|
return true;
|
}
|
for (int i = 0; i < achievements.Count; i++)
|
{
|
var id = achievements[i];
|
Achievement achievement;
|
if (model.TryGetAchievement(id, out achievement) && !achievement.completed)
|
{
|
return false;
|
}
|
}
|
|
return true;
|
}
|
|
public int GetDoingAchievement()
|
{
|
var achievementId = 0;
|
for (int i = 0; i < achievements.Count; i++)
|
{
|
var id = achievements[i];
|
Achievement achievement;
|
|
if (model.TryGetAchievement(id, out achievement) && !achievement.completed)
|
{
|
return id;
|
}
|
|
achievementId = id;
|
}
|
|
return achievementId;
|
}
|
|
public int GetLastAchievement()
|
{
|
if (achievements.Count == 0)
|
{
|
return 0;
|
}
|
else
|
{
|
var achievementId = GetDoingAchievement();
|
Achievement doingAchievement;
|
if (model.TryGetAchievement(achievementId, out doingAchievement) && doingAchievement.completed)
|
{
|
return achievementId;
|
}
|
return achievements[achievements.Count - 1];
|
}
|
}
|
|
private int AchievementCompare(int _lhs, int _rhs)
|
{
|
var configA = SuccessConfig.Get(_lhs);
|
var configB = SuccessConfig.Get(_rhs);
|
|
return configA.ReOrder.CompareTo(configB.ReOrder);
|
}
|
|
public static int Compare(AchievementGroup _lhs, AchievementGroup _rhs)
|
{
|
var awardableA = _lhs.IsAwardable();
|
var awardableB = _rhs.IsAwardable();
|
|
if (awardableA != awardableB)
|
{
|
return awardableA ? -1 : 1;
|
}
|
else
|
{
|
var completedA = _lhs.IsCompleted();
|
var completedB = _rhs.IsCompleted();
|
if (completedA != completedB)
|
{
|
return completedA.CompareTo(completedB);
|
}
|
else if (completedA && completedB)
|
{
|
return _lhs.group < _rhs.group ? -1 : 1;
|
}
|
else
|
{
|
var idA = _lhs.GetDoingAchievement();
|
var idB = _rhs.GetDoingAchievement();
|
|
var configA = SuccessConfig.Get(idA);
|
var configB = SuccessConfig.Get(idB);
|
|
if (configA == null)
|
{
|
return 1;
|
}
|
else if (configB == null)
|
{
|
return -1;
|
}
|
else if (configA == null && configB == null)
|
{
|
return 0;
|
}
|
else
|
{
|
return configA.ReOrder < configB.ReOrder ? -1 : 1;
|
}
|
}
|
}
|
}
|
|
}
|
|
public struct PotentialBook
|
{
|
public int itemId;
|
public int needCount;
|
public int successRate;
|
public int levelUpId;
|
|
public PotentialBook(int _itemId, int _needCount, int _successRate, int _levelUpId)
|
{
|
this.itemId = _itemId;
|
this.needCount = _needCount;
|
this.successRate = _successRate;
|
this.levelUpId = _levelUpId;
|
}
|
|
}
|
|
public struct VIPKillNPCTreasure
|
{
|
public int level;
|
public long currentExp;
|
}
|
|
public class TreasureStage
|
{
|
public int id { get; private set; }
|
|
public int stage { get; set; }
|
public TreasureStageUnlock unlockType { get; private set; }
|
public Dictionary<int, int> propertyDict { get; private set; }
|
public Dictionary<int, int> skillDict { get; private set; }
|
public int func { get; private set; }
|
public Item item { get; private set; }
|
public int treasure { get; private set; }
|
public int treasureSoul { get; private set; }
|
public int exp { get; set; }
|
public int powerEx { get; set; }
|
public int stateSfxId { get; private set; }
|
public const int selectedSfxId = 5144;
|
public string sfxGotState { get; private set; }
|
public string sfxUnGotState { get; private set; }
|
|
public TreasureStage(TreasureUpConfig _config)
|
{
|
id = _config.ID;
|
unlockType = TreasureStageUnlock.None;
|
if (_config.UnLockFuncID != 0)
|
{
|
unlockType = TreasureStageUnlock.Func;
|
func = _config.UnLockFuncID;
|
}
|
else if (_config.UnLockSkill != null && _config.UnLockSkill.Length > 1)
|
{
|
unlockType = TreasureStageUnlock.Skill;
|
skillDict = new Dictionary<int, int>();
|
for (int i = 0; i < _config.UnLockSkill.Length; i++)
|
{
|
skillDict.Add(i + 1, _config.UnLockSkill[i]);
|
}
|
}
|
else if (!string.IsNullOrEmpty(_config.AddAttr))
|
{
|
unlockType = TreasureStageUnlock.Property;
|
propertyDict = ConfigParse.GetDic<int, int>(_config.AddAttr);
|
}
|
else if (_config.ActiveMWID != 0)
|
{
|
unlockType = TreasureStageUnlock.Treasure;
|
treasure = _config.ActiveMWID;
|
}
|
else if (_config.SoulID != 0)
|
{
|
unlockType = TreasureStageUnlock.TreasureSoul;
|
treasureSoul = _config.SoulID;
|
}
|
else if (!string.IsNullOrEmpty(_config.ItemAward))
|
{
|
unlockType = TreasureStageUnlock.Item;
|
var itemArray = LitJson.JsonMapper.ToObject<int[]>(_config.ItemAward);
|
if (itemArray != null && itemArray.Length > 0)
|
{
|
item = new Item()
|
{
|
id = itemArray[0],
|
count = itemArray.Length > 1 ? itemArray[1] : 1,
|
bind = itemArray.Length > 2 ? (itemArray[2] == 1) : false,
|
};
|
}
|
}
|
|
exp = _config.NeedExp;
|
stage = _config.LV;
|
powerEx = _config.PowerEx;
|
|
switch (unlockType)
|
{
|
case TreasureStageUnlock.Property:
|
stateSfxId = propertyDict.ContainsKey(6) ? 5142 : 5139;
|
sfxGotState = propertyDict.ContainsKey(6) ? "Effect_FaBao_Icon_ShengMing" : "Effect_FaBao_Icon_GongJi";
|
sfxUnGotState = propertyDict.ContainsKey(6) ? "Effect_FaBao_Icon_ShengMing" : "Effect_FaBao_Icon_GongJi";
|
break;
|
default:
|
stateSfxId = 5141;
|
sfxGotState = "Effect_FaBao_Icon_JiNeng_01";
|
sfxUnGotState = "Effect_FaBao_Icon_JiNeng_02";
|
break;
|
}
|
}
|
|
public int GetSkill(int _job)
|
{
|
if (skillDict.ContainsKey(_job))
|
{
|
return skillDict[_job];
|
}
|
return 0;
|
}
|
|
public int GetFightPower()
|
{
|
switch (unlockType)
|
{
|
case TreasureStageUnlock.Property:
|
return UIHelper.GetFightPower(propertyDict);
|
case TreasureStageUnlock.Skill:
|
var _job = PlayerDatas.Instance.baseData.Job;
|
var _skillCfg = SkillConfig.Get(GetSkill(_job));
|
if (_skillCfg != null)
|
{
|
return _skillCfg.FightPower;
|
}
|
break;
|
}
|
return 0;
|
}
|
}
|
|
public class TreasureDungeon
|
{
|
public int treasureId;
|
public List<TreasureDungeonInfo> dungeonInfos = new List<TreasureDungeonInfo>();
|
private int m_Level = 0;
|
|
public int currentLevel
|
{
|
get
|
{
|
var model = ModelCenter.Instance.GetModel<TreasureModel>();
|
Treasure treasure;
|
if (model.TryGetTreasure(treasureId, out treasure)
|
&& treasure.state == TreasureState.Collected)
|
{
|
return maxLevel;
|
}
|
return m_Level;
|
}
|
set
|
{
|
m_Level = value;
|
}
|
}
|
|
public int maxLevel { get; private set; }
|
|
public Redpoint challengeRedpoint;
|
|
public TreasureDungeon(int treasureId,Redpoint challengeRedpoint)
|
{
|
this.treasureId = treasureId;
|
this.challengeRedpoint = challengeRedpoint;
|
}
|
|
public void ParseDungeonInfo(TreasureDungeonConfig config)
|
{
|
if (dungeonInfos.FindIndex((x) =>
|
{
|
return x.level == config.Level;
|
}) == -1)
|
{
|
var json = LitJson.JsonMapper.ToObject(config.Attr);
|
var propertyDict = new Dictionary<int, int>();
|
foreach (var key in json.Keys)
|
{
|
var property = int.Parse(key);
|
var value = int.Parse(json[key].ToString());
|
propertyDict.Add(property, value);
|
}
|
var dungeonInfo = new TreasureDungeonInfo()
|
{
|
key = config.ID,
|
fightPower = config.fightPower,
|
level = config.Level,
|
propertyDict = propertyDict,
|
lineId = config.LineID
|
};
|
dungeonInfos.Add(dungeonInfo);
|
|
if (config.Level > maxLevel)
|
{
|
maxLevel = config.Level;
|
}
|
}
|
}
|
|
public TreasureDungeonInfo Get(int level)
|
{
|
return dungeonInfos.Find((x) =>
|
{
|
return x.level == level;
|
});
|
}
|
|
public Dictionary<int, int> GetUpperProperty(int level)
|
{
|
var lastDungeonInfo = Get(level - 1);
|
var currentDungeonInfo = Get(level);
|
if (currentDungeonInfo.Equals(default(TreasureDungeonInfo)))
|
{
|
return null;
|
}
|
var dict = new Dictionary<int, int>();
|
foreach (var key in currentDungeonInfo.propertyDict.Keys)
|
{
|
if (level == 1)
|
{
|
dict.Add(key, currentDungeonInfo.propertyDict[key]);
|
}
|
else
|
{
|
if (lastDungeonInfo.propertyDict.ContainsKey(key))
|
{
|
if (lastDungeonInfo.propertyDict[key] >= currentDungeonInfo.propertyDict[key])
|
{
|
continue;
|
}
|
dict.Add(key, currentDungeonInfo.propertyDict[key] - lastDungeonInfo.propertyDict[key]);
|
}
|
else
|
{
|
dict.Add(key, currentDungeonInfo.propertyDict[key]);
|
}
|
}
|
}
|
return dict;
|
}
|
}
|
|
public struct TreasureDungeonInfo
|
{
|
public int key;
|
public int lineId;
|
public int level;
|
public Dictionary<int, int> propertyDict;
|
public int fightPower;
|
}
|
|
public enum TreasureStageUnlock
|
{
|
None,
|
Property,
|
Skill,
|
Func,
|
Item,
|
Treasure,
|
TreasureSoul,
|
}
|
}
|
|
|
|