1 package cz.cuni.amis.pogamut.ut2004.bot.command;
2
3 import java.util.logging.Logger;
4
5 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
6 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
7 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.SendMessage;
8
9 /**
10 * Class providing Pogamut2 UT2004 communication commands - send message, set
11 * dialogs, text bubble...
12 *
13 * @author Michal 'Knight' Bida
14 */
15 public class Communication extends BotCommands {
16
17 /**
18 * Sends global message to UT2004 in-game chat. Everyone will see it, bots
19 * will receive information too.
20 *
21 * (issues GB MESSAGE command)
22 *
23 * @param text
24 * Text of the message to send.
25 *
26 * @see sendTeamTextMessage(String)
27 * @see sendPrivateTextMessage(UnrealId, String)
28 */
29 public void sendGlobalTextMessage(String text) {
30 SendMessage message = new SendMessage();
31
32 message.setGlobal(true);
33 message.setText(text);
34 // This will cause that the text bubble won't be shown.
35 message.setFadeOut((double)-1);
36
37 agent.getAct().act(message);
38 }
39
40 /**
41 * Sends a message to UT2004 in-game chat. Only members of the bot current
42 * team will see it. If there are no teams (e.g. no team game, just simple
43 * deathmatch) it will be handled as global message.
44 *
45 * (issues GB MESSAGE command)
46 *
47 * @param text
48 * Text of the message to send.
49 *
50 * @see sendGlobalTextMessage(String)
51 * @see sendPrivateTextMessage(UnrealId, String)
52 */
53 public void sendTeamTextMessage(String text) {
54 SendMessage message = new SendMessage();
55
56 message.setGlobal(false);
57 message.setText(text);
58 // This will cause that the text bubble won't be shown.
59 message.setFadeOut((double)-1);
60
61 agent.getAct().act(message);
62 }
63
64 /**
65 * Sends a private message to desired bot (specified by Id). There will be
66 * added "Private:" string in front of the message. Works just for GameBots
67 * RemoteBots. If the id is not of RemoteBot nothing will happen - the
68 * message won't be sent to anyone.
69 *
70 * @param id
71 * Here we can specify Id of the bot, that will receive this
72 * message privately.
73 * @param text
74 * Text of the message to send.
75 *
76 * @see sendGlobalTextMessage(String)
77 * @see sendTeamTextMessage(String)
78 *
79 */
80 public void sendPrivateTextMessage(UnrealId id, String text) {
81 SendMessage message = new SendMessage();
82
83 message.setId(id);
84 message.setText(text);
85 // This will cause that the text bubble won't be shown.
86 message.setFadeOut((double)-1);
87
88 agent.getAct().act(message);
89 }
90
91 /**
92 * Sends a global message to UT2004 in-game chat and sets the text bubble
93 * visible to all human players above the bot head. Everyone will receive
94 * the message. The bubble will stay as long as specified in fadeOut
95 * variable.
96 *
97 * @param text
98 * Text of the message and bubble.
99 * @param fadeOut
100 * Sets how long the bubble should stay visible (in seconds,
101 * counted as 12 + fadeOut seconds - probably due to some UT
102 * mechanics). If -1 the bubble won't be shown at all.
103 *
104 * @see sendPrivateBubbleMessage(UnrealId, String, double)
105 * @see sendPrivateBubbleMessage(UnrealId, String, double)
106 */
107 public void sendGlobalBubbleMessage(String text, double fadeOut) {
108 SendMessage message = new SendMessage();
109
110 message.setGlobal(true);
111 message.setText(text);
112 message.setFadeOut(fadeOut);
113
114 agent.getAct().act(message);
115 }
116
117 /**
118 * Sends a message to UT2004 in-game chat and sets the text bubble visible
119 * to all human players above the bot head. The message will be send just to
120 * players and bots from the same team (although other human players will
121 * still see it through text bubble). If not team game, treated as global
122 * message. The bubble will stay as long as specified in fadeOut variable.
123 *
124 * @param text
125 * Text of the message and bubble.
126 * @param fadeOut
127 * Sets how long the bubble should stay visible (in seconds,
128 * counted as 12 + fadeOut seconds - probably due to some UT
129 * mechanics). If -1 the bubble won't be shown at all.
130 *
131 * @see sendGlobalBubbleMessage(String, double)
132 * @see sendPrivateBubbleMessage(UnrealId, String, double)
133 */
134 public void sendTeamBubbleMessage(String text, double fadeOut) {
135 SendMessage message = new SendMessage();
136
137 message.setGlobal(false);
138 message.setText(text);
139 message.setFadeOut(fadeOut);
140
141 agent.getAct().act(message);
142 }
143
144 /**
145 * Sends a private message to desired bot (specified by Id). There will be
146 * added "Private:" string in front of the message. Also sets the text
147 * bubble above the bot head, that will be visible to all human players. The
148 * message can be received just by GameBots RemoteBots (although all human
149 * players will see it through text bubble).
150 *
151 * @param id
152 * Here we can specify Id of the bot, that will receive this
153 * message privately. Other players will see this message through
154 * bubble too.
155 * @param text
156 * Text of the message and bubble.
157 * @param fadeOut
158 * Sets how long the bubble should stay visible (in seconds,
159 * counted as 12 + fadeOut seconds - probably due to some UT
160 * mechanics). If -1 the bubble won't be shown at all.
161 *
162 * @see sendGlobalBubbleMessage(String, double)
163 * @see sendTeamBubbleMessage(String, double)
164 */
165 public void sendPrivateBubbleMessage(UnrealId id, String text,
166 double fadeOut) {
167 SendMessage message = new SendMessage();
168
169 message.setId(id);
170 message.setText(text);
171 message.setFadeOut(fadeOut);
172
173 agent.getAct().act(message);
174 }
175
176 /**
177 * Constructor. Setups the command module based on given agent and logger.
178 *
179 * @param agent
180 * AbstractUT2004Bot we will send commands for
181 * @param log
182 * Logger to be used for logging runtime/debug info.
183 */
184 public Communication(UT2004Bot agent, Logger log) {
185 super(agent, log);
186 }
187
188 }