少年修仙传客户端代码仓库
hch
2019-10-31 3c35f85432d317061f09c93319108de899469d55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, July 16, 2019
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
 
namespace Snxxz.UI
{
    public class EquipStarMaterialSelectModel : Model
    {
        public event Action materialSelectEvent;
 
        List<string> selectedMaterials = new List<string>();
 
        EquipStarModel starModel { get { return ModelCenter.Instance.GetModel<EquipStarModel>(); } }
 
        public override void Init()
        {
 
        }
 
        public override void UnInit()
        {
 
        }
 
        public void InitMaterials(List<string> materials)
        {
            selectedMaterials.AddRange(materials);
        }
 
        public void AddMaterial(string guid)
        {
            if (CalculateSuccessRate() > 0.999f)
            {
                SysNotifyMgr.Instance.ShowTip("StarLevelUp6");
                return;
            }
 
            if (!selectedMaterials.Contains(guid))
            {
                selectedMaterials.Add(guid);
                if (materialSelectEvent != null)
                {
                    materialSelectEvent();
                }
            }
        }
 
        public void RemoveMaterial(string guid)
        {
            if (selectedMaterials.Contains(guid))
            {
                selectedMaterials.Remove(guid);
                if (materialSelectEvent != null)
                {
                    materialSelectEvent();
                }
            }
        }
 
        public bool IsSelectedMaterial(string guid)
        {
            return selectedMaterials.Contains(guid);
        }
 
        public void ClearSelectedMaterials()
        {
            selectedMaterials.Clear();
        }
 
        public List<string> GetSelectedMaterials()
        {
            return selectedMaterials;
        }
 
        public float CalculateSuccessRate()
        {
            var rate = 0f;
            var equipPosition = new Int2(starModel.selectedLevel.value, starModel.selectedPlace.value);
            foreach (var material in selectedMaterials)
            {
                rate += starModel.GetMaterialSuccessRate(equipPosition, material);
            }
            // 95%以上概率 则为100%
            if (rate >= 0.95 && rate < 1)
                rate = 1f;
            return rate;
        }
 
 
    }
 
}