1234567891011121314151617181920212223242526272829303132333435 |
- using System.Collections.Generic;
- using UnityEngine;
- using Random = System.Random;
- namespace Game
- {
- public class AttackRandomUtil
- {
- private static readonly Dictionary<int, int[]> CockAttackDict = new Dictionary<int, int[]>()
- {
- { 1, new int[] { 1, 2, 3, -1 } },
- { 2, new int[] { 2, 3, 4, -1 } },
- { 3, new int[] { 3, 4, 5, -1 } },
- { 4, new int[] { 1, 2, 4, -1 } },
- { 5, new int[] { 1, 2, 5, -1 } },
- { 6, new int[] { 2, 4, 5, -1 } },
- { 7, new int[] { 1, 3, 4, -1 } },
- };
- public static int GetRandomNumberFromDict(int cockId)
- {
- Debug.Log("cock id is " + cockId);
- if (CockAttackDict.ContainsKey(cockId))
- {
- var numbers = CockAttackDict[cockId];
- var random = new Random();
- var randomIndex = random.Next(0, numbers.Length);
- return numbers[randomIndex];
- }
- // 如果 key 不存在,可以返回一个默认值或抛出异常等处理方式
- return -1;
- }
- }
- }
|