AttackRandomUtil.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using Random = System.Random;
  4. namespace Game
  5. {
  6. public class AttackRandomUtil
  7. {
  8. private static readonly Dictionary<int, int[]> CockAttackDict = new Dictionary<int, int[]>()
  9. {
  10. { 1, new int[] { 1, 2, 3, -1 } },
  11. { 2, new int[] { 2, 3, 4, -1 } },
  12. { 3, new int[] { 3, 4, 5, -1 } },
  13. { 4, new int[] { 1, 2, 4, -1 } },
  14. { 5, new int[] { 1, 2, 5, -1 } },
  15. { 6, new int[] { 2, 4, 5, -1 } },
  16. { 7, new int[] { 1, 3, 4, -1 } },
  17. };
  18. public static int GetRandomNumberFromDict(int cockId)
  19. {
  20. Debug.Log("cock id is " + cockId);
  21. if (CockAttackDict.ContainsKey(cockId))
  22. {
  23. var numbers = CockAttackDict[cockId];
  24. var random = new Random();
  25. var randomIndex = random.Next(0, numbers.Length);
  26. return numbers[randomIndex];
  27. }
  28. // 如果 key 不存在,可以返回一个默认值或抛出异常等处理方式
  29. return -1;
  30. }
  31. }
  32. }