Bots use normal chat, with effects

This commit is contained in:
RedSparr0w
2019-11-23 20:40:56 +13:00
parent 576bee32c3
commit 2104fd9918
7 changed files with 17 additions and 25 deletions
+11 -18
View File
@@ -3,12 +3,8 @@ package redone.game.bots;
import redone.Server; import redone.Server;
import redone.game.items.ItemAssistant; import redone.game.items.ItemAssistant;
import redone.game.players.Client; import redone.game.players.Client;
import redone.game.players.Player;
import redone.game.players.PlayerHandler;
import redone.util.GameLogger;
import redone.util.Misc; import redone.util.Misc;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.*;
@@ -68,23 +64,20 @@ public class Bot {
String item_name = ItemAssistant.getItemName(item_id).toLowerCase(); String item_name = ItemAssistant.getItemName(item_id).toLowerCase();
int value = BotHandler.getItemPrice(botClient.myShopId, item_id); int value = BotHandler.getItemPrice(botClient.myShopId, item_id);
if (value <= 0) return; if (value <= 0) return;
botClient.forcedChat("Selling " + item_name + " " + formatSellPrice(value) + " ea");
/*
Real chat - Disabled for now, can't get it to function correctly
// Add some color and effects String _message = "Selling " + item_name + " " + formatSellPrice(value) + " ea - " + botClient.playerName;
botClient.setChatTextColor(9);
botClient.setChatTextEffects(2);
String message = "Selling " + item_name + " " + formatSellPrice(value) + " ea - " + botClient.playerName; // Disable the force chat for now, maybe use that instead, maybe not
// Need to figure out how to calculate this //botClient.forcedChat("Selling " + item_name + " " + formatSellPrice(value) + " ea");
botClient.setChatTextSize((byte) 29);
// This is wrong too // Normal chat from here down:
botClient.setChatText(message.getBytes(StandardCharsets.UTF_8)); botClient.setChatTextColor(Misc.random(11));
// Not a clue what this does botClient.setChatTextEffects(Misc.random(5));
botClient.inStream.readBytes_reverseA(botClient.getChatText(), botClient.getChatTextSize(), 0); Misc.textPack(botClient.inStream, _message);
botClient.setChatTextSize((byte) botClient.inStream.currentOffset);
botClient.setChatText(botClient.inStream.buffer);
botClient.inStream.currentOffset = 0;
botClient.setChatTextUpdateRequired(true); botClient.setChatTextUpdateRequired(true);
*/
} }
private String formatSellPrice(int price) { private String formatSellPrice(int price) {
+6 -6
View File
@@ -218,14 +218,14 @@ public class Misc {
return new String(buf, 0, buf.length); return new String(buf, 0, buf.length);
} }
public static void textPack(byte packedData[], java.lang.String text) { public static void textPack(Stream inStream, String text) {
if (text.length() > 80) { if (text.length() > 80) {
text = text.substring(0, 80); text = text.substring(0, 80);
} }
text = text.toLowerCase(); text = text.toLowerCase();
int carryOverNibble = -1; int carryOverNibble = -1;
int ofs = 0; inStream.currentOffset = 0;
for (int idx = 0; idx < text.length(); idx++) { for (int idx = 0; idx < text.length(); idx++) {
char c = text.charAt(idx); char c = text.charAt(idx);
int tableIdx = 0; int tableIdx = 0;
@@ -242,19 +242,19 @@ public class Misc {
if (tableIdx < 13) { if (tableIdx < 13) {
carryOverNibble = tableIdx; carryOverNibble = tableIdx;
} else { } else {
packedData[ofs++] = (byte) tableIdx; inStream.buffer[inStream.currentOffset++] = (byte) tableIdx;
} }
} else if (tableIdx < 13) { } else if (tableIdx < 13) {
packedData[ofs++] = (byte) ((carryOverNibble << 4) + tableIdx); inStream.buffer[inStream.currentOffset++] = (byte) ((carryOverNibble << 4) + tableIdx);
carryOverNibble = -1; carryOverNibble = -1;
} else { } else {
packedData[ofs++] = (byte) ((carryOverNibble << 4) + (tableIdx >> 4)); inStream.buffer[inStream.currentOffset++] = (byte) ((carryOverNibble << 4) + (tableIdx >> 4));
carryOverNibble = tableIdx & 0xf; carryOverNibble = tableIdx & 0xf;
} }
} }
if (carryOverNibble != -1) { if (carryOverNibble != -1) {
packedData[ofs++] = (byte) (carryOverNibble << 4); inStream.buffer[inStream.currentOffset++] = (byte) (carryOverNibble << 4);
} }
} }
@@ -161,7 +161,6 @@ public class Stream {
for (int k = j + i - 1; k >= j; k--) { for (int k = j + i - 1; k >= j; k--) {
buffer[currentOffset++] = abyte0[k]; buffer[currentOffset++] = abyte0[k];
} }
} }
public void readBytes_reverseA(byte abyte0[], int i, int j) { public void readBytes_reverseA(byte abyte0[], int i, int j) {