105 lines
4.6 KiB
C#
105 lines
4.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UniRx;
|
|
using UnityEngine.Assertions;
|
|
using GameCore;
|
|
using asap.core;
|
|
|
|
public class EventBingoSystem
|
|
{
|
|
private static readonly int[] BingoStates =
|
|
{
|
|
0b0000000000000000000011111,
|
|
0b0000000000000001111100000,
|
|
0b0000000000111110000000000,
|
|
0b0000011111000000000000000,
|
|
0b1111100000000000000000000,
|
|
0b1000010000100001000010000,
|
|
0b0100001000010000100001000,
|
|
0b0010000100001000010000100,
|
|
0b0001000010000100001000010,
|
|
0b0000100001000010000100001,
|
|
0b1000001000001000001000001,
|
|
0b0000100010001000100010000,
|
|
0b1000100000000000000010001
|
|
};
|
|
|
|
private static readonly int[] NearBingoStates =
|
|
{
|
|
0b0000000000000000000011110, 0b0000000000000000000011101, 0b0000000000000000000011011, 0b0000000000000000000010111, 0b0000000000000000000001111,
|
|
0b0000000000000001111000000, 0b0000000000000001110100000, 0b0000000000000001101100000, 0b0000000000000001011100000, 0b0000000000000000111100000,
|
|
0b0000000000111100000000000, 0b0000000000111010000000000, 0b0000000000110110000000000, 0b0000000000101110000000000, 0b0000000000011110000000000,
|
|
0b0000011110000000000000000, 0b0000011101000000000000000, 0b0000011011000000000000000, 0b0000010111000000000000000, 0b0000001111000000000000000,
|
|
0b1111000000000000000000000, 0b1110100000000000000000000, 0b1101100000000000000000000, 0b1011100000000000000000000, 0b0111100000000000000000000,
|
|
0b1000010000100001000000000, 0b1000010000100000000010000, 0b1000010000000001000010000, 0b1000000000100001000010000, 0b0000010000100001000010000,
|
|
0b0100001000010000100000000, 0b0100001000010000000001000, 0b0100001000000000100001000, 0b0100000000010000100001000, 0b0000001000010000100001000,
|
|
0b0010000100001000010000000, 0b0010000100001000000000100, 0b0010000100000000010000100, 0b0010000000001000010000100, 0b0000000100001000010000100,
|
|
0b0001000010000100001000000, 0b0001000010000100000000010, 0b0001000010000000001000010, 0b0001000000000100001000010, 0b0000000010000100001000010,
|
|
0b0000100001000010000100000, 0b0000100001000010000000001, 0b0000100001000000000100001, 0b0000100000000010000100001, 0b0000000001000010000100001,
|
|
0b1000001000001000001000000, 0b1000001000001000000000001, 0b1000001000000000001000001, 0b1000000000001000001000001, 0b0000001000001000001000001,
|
|
0b0000100010001000100000000, 0b0000100010001000000010000, 0b0000100010000000100010000, 0b0000100000001000100010000, 0b0000000010001000100010000,
|
|
0b1000100000000000000010000, 0b1000100000000000000000001, 0b1000000000000000000010001, 0b0000100000000000000010001,
|
|
};
|
|
|
|
public static List<int> GenerateBoardNumbers(System.Random rng)
|
|
{
|
|
var res = new List<int>();
|
|
var numPool = Enumerable.Range(1, 99).ToList();
|
|
for (int i = 0; i < EventBingoModel.NumberCount; i++)
|
|
{
|
|
var index = rng.Next(numPool.Count);
|
|
res.Add(numPool[index]);
|
|
numPool.RemoveAt(index);
|
|
}
|
|
return res;
|
|
}
|
|
|
|
public static int PickRandomNumberFromList(List<int> nums, System.Random rng)
|
|
{
|
|
Assert.IsTrue(nums is { Count: >= 1 }, "[EventBingo] Number list is empty.");
|
|
var idx = rng.Next(nums.Count);
|
|
var n = nums[idx];
|
|
nums.RemoveAt(idx);
|
|
return n;
|
|
}
|
|
|
|
public static int CheckBingo(int state, out int[] indices)
|
|
{
|
|
int res = 0;
|
|
var pickedIndices = new HashSet<int>();
|
|
for (int i = 0; i < BingoStates.Length; i++)
|
|
{
|
|
if ((state & BingoStates[i]) != BingoStates[i])
|
|
continue;
|
|
var bingoIndices = FtMathUtils.BitWisePositionScan(BingoStates[i]);
|
|
foreach(var idx in bingoIndices)
|
|
pickedIndices.Add(idx);
|
|
res++;
|
|
}
|
|
indices = pickedIndices.ToArray();
|
|
return res;
|
|
}
|
|
|
|
public static int[] CheckNearBingoIndices(int state)
|
|
{
|
|
var res = new HashSet<int>();
|
|
for (int i = 0; i < NearBingoStates.Length; i++)
|
|
{
|
|
if ((state & NearBingoStates[i]) != NearBingoStates[i])
|
|
continue;
|
|
var stateIndices = FtMathUtils.BitWisePositionScan(NearBingoStates[i]);
|
|
foreach (var idx in stateIndices)
|
|
res.Add(idx);
|
|
}
|
|
return res.ToArray();
|
|
}
|
|
|
|
public static void GrantReward(ItemData reward)
|
|
{
|
|
// Debug.Log($"[EventBingo] Grant Reward {reward.id} * {reward.count}.");
|
|
// if (reward.id == )
|
|
var e = new DeferredRewardStashService.EventStashItem { Item = reward };
|
|
GContext.Publish(e);
|
|
}
|
|
}
|