| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using CommonAI.ZoneClient;
- using CommonLang;
- using CommonLang.Concurrent;
- using CommonLang.Reflection;
- using CommonRPG.Protocol.Client;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- namespace CommonRPG.Client.BotTest.Runner.Modules
- {
- public class ModuleChat : RunnerModule
- {
- #region ChatData
- private static AtomicInteger s_index = new AtomicInteger(0);
- private static List<string> s_chat_list = new List<string>();
- static ModuleChat()
- {
- var all = File.ReadAllLines(Application.StartupPath + @"\ChatData.txt");
- foreach (var line in all)
- {
- if (line.Trim().Length > 0)
- {
- var kv = line.Split(new char[] { ':' }, 2);
- if (kv.Length == 2)
- {
- s_chat_list.Add(kv[1]);
- }
- else
- {
- s_chat_list.Add(line);
- }
- }
- }
- }
- #endregion
- private Random random = new Random();
- public ModuleChat(BotRunner r) : base(r)
- {
- base.Client.OnZoneActorEntered += Client_OnZoneActorEntered;
- }
- private void Client_OnZoneActorEntered(CommonAI.ZoneClient.ZoneActor obj)
- {
- obj.Parent.AddTimePeriodicMS(Config.ChatIntervalMS, (t) =>
- {
- if (base.IsEnable)
- {
- do_interval();
- }
- });
- }
- private void do_interval()
- {
- var text = s_chat_list[(int)(s_index.GetAndIncrement() % s_chat_list.Count)];
- try
- {
- var channel = CUtils.GetRandomInArray(Config.ChatChannels, this.random);
- base.Runner.Client.GameClient.Request<ClientChatResponse>(new ClientChatRequest()
- {
- channel_type = (short)channel,
- content = text,
- }, (err, rsp) =>
- {
- if (err != null) log.Error("SentChat : " + err.Message);
- else log.Info("SentChat : " + rsp);
- });
- // bot.chat_SendChat((err, rsp) =>
- // {
- // if (err != null) log.Error("SentChat : " + err.Message);
- // else log.Info("SentChat : " + rsp);
- // }, text, "", channel);
- }
- catch (Exception err)
- {
- log.Error(err.Message, err);
- }
- }
- //-------------------------------------------------------------------------------------------------------------------
- [Desc("聊天配置")]
- [Expandable]
- public class Config : RunnerModuleConfig
- {
- [Desc("聊天发送间隔")]
- public static int ChatIntervalMS = 5000;
- [Desc("聊天发送频道")]
- public static ChatChannel[] ChatChannels = new ChatChannel[]
- {
- ChatChannel.World,
- ChatChannel.Trade,
- };
- public override string ToString()
- {
- return "聊天配置";
- }
- }
- public enum ChatChannel
- {
- World = ClientChatRequest.CHANNEL_TYPE_WORLD,
- Trade = ClientChatRequest.CHANNEL_TYPE_TRADE,
- Guild = ClientChatRequest.CHANNEL_TYPE_GUILD,
- Team = ClientChatRequest.CHANNEL_TYPE_TEAM,
- Battle = ClientChatRequest.CHANNEL_TYPE_BATTLE,
- Area = ClientChatRequest.CHANNEL_TYPE_AREA,
- }
- }
- }
|