124 lines
4.3 KiB
C#
124 lines
4.3 KiB
C#
|
|
using asap.core;
|
|
using cfg;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
public enum RobotDuelChatType
|
|
{
|
|
Start = 1,
|
|
FishingSuccess = 2,
|
|
OpponetFishingSuccess = 3,
|
|
OpponetFishingFail = 4,
|
|
FirstLastFishStart = 5,
|
|
FirstLastFishSuccess = 6,
|
|
EndVictory = 7,
|
|
EndDefeat = 8
|
|
|
|
}
|
|
public class DuelRobotChatModel : IDuelChatModel
|
|
{
|
|
public int RoleID { get; set; }
|
|
EventSoloRobotBehavior enemyRobotBehavior;
|
|
List<int> RobotBehaviorTimeDelay = new List<int>() { 0, 2 };
|
|
public DuelRobotChatModel()
|
|
{
|
|
GetEventSoloRobotBehavior();
|
|
}
|
|
public void ReceiveMessage(int message)
|
|
{
|
|
GContext.Publish(new DuelChatEvent(RoleID, message));
|
|
}
|
|
/// <summary>
|
|
/// 机器人 读表获取消息 转发本地
|
|
/// </summary>
|
|
/// <param name="messageType"></param>
|
|
public void SendMessage(int messageType)
|
|
{
|
|
RobotDuelChatType robotDuelChatType = (RobotDuelChatType)messageType;
|
|
Debug.Log($"RobotDuelChatType: {robotDuelChatType}");
|
|
int prob = 0;
|
|
List<int> ints = new List<int>();
|
|
switch (robotDuelChatType)
|
|
{
|
|
case RobotDuelChatType.Start:
|
|
prob = enemyRobotBehavior.Start[0][0];
|
|
ints = enemyRobotBehavior.Start[1];
|
|
break;
|
|
case RobotDuelChatType.FishingSuccess:
|
|
prob = enemyRobotBehavior.FishingSuccess[0][0];
|
|
ints = enemyRobotBehavior.FishingSuccess[1];
|
|
break;
|
|
case RobotDuelChatType.OpponetFishingSuccess:
|
|
prob = enemyRobotBehavior.OpponetFishingSuccess[0][0];
|
|
ints = enemyRobotBehavior.OpponetFishingSuccess[1];
|
|
break;
|
|
case RobotDuelChatType.OpponetFishingFail:
|
|
prob = enemyRobotBehavior.OpponetFishingFail[0][0];
|
|
ints = enemyRobotBehavior.OpponetFishingFail[1];
|
|
break;
|
|
case RobotDuelChatType.FirstLastFishStart:
|
|
prob = enemyRobotBehavior.FirstLastFishStart[0][0];
|
|
ints = enemyRobotBehavior.FirstLastFishStart[1];
|
|
break;
|
|
case RobotDuelChatType.FirstLastFishSuccess:
|
|
prob = enemyRobotBehavior.FirstLastFishSuccess[0][0];
|
|
ints = enemyRobotBehavior.FirstLastFishSuccess[1];
|
|
break;
|
|
case RobotDuelChatType.EndVictory:
|
|
prob = enemyRobotBehavior.EndVictory[0][0];
|
|
ints = enemyRobotBehavior.EndVictory[1];
|
|
break;
|
|
case RobotDuelChatType.EndDefeat:
|
|
prob = enemyRobotBehavior.EndDefeat[0][0];
|
|
ints = enemyRobotBehavior.EndDefeat[1];
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
int randomValue = UnityEngine.Random.Range(0, 100);
|
|
//Debug.Log($"机器人消息: {robotDuelChatType} ID {enemyRobotBehavior.ID} prob:{prob} randomValue:{randomValue}");
|
|
if (prob == 0 || prob < randomValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int index = UnityEngine.Random.Range(0, ints.Count);
|
|
int messageId = ints[index];
|
|
SendMessageDelay(messageId);
|
|
}
|
|
|
|
async void SendMessageDelay(int messageId)
|
|
{
|
|
try
|
|
{
|
|
float delay = UnityEngine.Random.Range(RobotBehaviorTimeDelay[0] * 1f, RobotBehaviorTimeDelay[1]);
|
|
await Awaiters.Seconds(delay);
|
|
ReceiveMessage(messageId);
|
|
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError($" [RobotChat] SendMessageDelay error: {e.Message}");
|
|
}
|
|
}
|
|
|
|
void GetEventSoloRobotBehavior()
|
|
{
|
|
RobotBehaviorTimeDelay = GContext.container.Resolve<Tables>().TbEventSoloConfig.RobotBehaviorTimeDelay;
|
|
List<EventSoloRobotBehavior> robotBehaviors = GContext.container.Resolve<Tables>().TbEventSoloRobotBehavior.DataList;
|
|
int allweight = robotBehaviors.Select(x => x.Weight).Sum();
|
|
int randomValue = UnityEngine.Random.Range(0, allweight);
|
|
int currentWeight = 0;
|
|
foreach (var behavior in robotBehaviors)
|
|
{
|
|
currentWeight += behavior.Weight;
|
|
if (randomValue < currentWeight)
|
|
{
|
|
enemyRobotBehavior = behavior;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|