|
@@ -23,6 +23,7 @@ void ScriptTrader::activate(void) {
|
|
|
|
|
|
|
|
|
state = 1;
|
|
|
+ percent = 5.0;
|
|
|
to_server("I");
|
|
|
}
|
|
|
|
|
@@ -31,6 +32,66 @@ void ScriptTrader::deactivate(void) { notify(); }
|
|
|
void ScriptTrader::server_line(const std::string &line,
|
|
|
const std::string &raw_line) {
|
|
|
|
|
|
+ if (line == "Docking...") {
|
|
|
+ last_offer = 0;
|
|
|
+ final_offer = 0;
|
|
|
+ initial_offer = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startswith(line, "We'll buy them for ")) {
|
|
|
+
|
|
|
+ std::string offer = line.substr(19);
|
|
|
+ replace(offer, ",", "");
|
|
|
+ initial_offer = stoi(offer);
|
|
|
+ BUGZ_LOG(fatal) << "Buying, initial: " << initial_offer;
|
|
|
+ buying = true;
|
|
|
+ last_offer = 0;
|
|
|
+ final_offer = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startswith(line, "We'll sell them for ")) {
|
|
|
+
|
|
|
+ std::string offer = line.substr(20);
|
|
|
+ replace(offer, ",", "");
|
|
|
+ initial_offer = stoi(offer);
|
|
|
+ BUGZ_LOG(fatal) << "Selling, initial: " << initial_offer;
|
|
|
+ buying = false;
|
|
|
+ last_offer = 0;
|
|
|
+ final_offer = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startswith(line, "Our final offer is ")) {
|
|
|
+
|
|
|
+ std::string offer = line.substr(20);
|
|
|
+ replace(offer, ",", "");
|
|
|
+ final_offer = stoi(offer);
|
|
|
+ BUGZ_LOG(fatal) << "Final offer: " << final_offer;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (startswith(line, "You have ")) {
|
|
|
+ if (initial_offer != 0) {
|
|
|
+
|
|
|
+ int success;
|
|
|
+ if (buying)
|
|
|
+ success = 0;
|
|
|
+ else
|
|
|
+ success = director.galaxy.meta["ship"]["holds"]["total"].as<int>();
|
|
|
+
|
|
|
+ std::string text = std::to_string(success);
|
|
|
+ text.append(" empty cargo holds.");
|
|
|
+ if (endswith(line, text)) {
|
|
|
+ BUGZ_LOG(fatal) << "Trade SUCCESS!";
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void ScriptTrader::server_prompt(const std::string &prompt) {
|
|
@@ -53,7 +114,6 @@ void ScriptTrader::server_prompt(const std::string &prompt) {
|
|
|
|
|
|
|
|
|
bool have_buy = false;
|
|
|
- char foe[4] = "foe";
|
|
|
int active_buy = 0;
|
|
|
int active_sell = 0;
|
|
|
|
|
@@ -72,7 +132,7 @@ void ScriptTrader::server_prompt(const std::string &prompt) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (port_buysell[0].foe[x]) {
|
|
|
+ if (!port_buysell[0].foe[x]) {
|
|
|
active_sell = 0;
|
|
|
} else {
|
|
|
active_sell = 1;
|
|
@@ -113,7 +173,8 @@ void ScriptTrader::server_prompt(const std::string &prompt) {
|
|
|
|
|
|
deactivate();
|
|
|
}
|
|
|
- if (state == 3) {
|
|
|
+
|
|
|
+ if (state == 2) {
|
|
|
if (director.current_sector == active_port) {
|
|
|
|
|
|
state = 3;
|
|
@@ -135,7 +196,56 @@ void ScriptTrader::server_prompt(const std::string &prompt) {
|
|
|
to_server("\r");
|
|
|
return;
|
|
|
}
|
|
|
+ if (in(prompt, " to buy ") && startswith(prompt, "How many holds of ")) {
|
|
|
+
|
|
|
+ char selling = tolower(prompt[18]);
|
|
|
+ BUGZ_LOG(fatal) << "Selling: " << selling;
|
|
|
+ for (int x = 0; x < 3; ++x) {
|
|
|
+ if (foe[x] == selling) {
|
|
|
+
|
|
|
+ if (trades.foe[x]) {
|
|
|
+
|
|
|
+ to_server("\r");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ to_server("0\r");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ if (startswith(prompt, "Your offer [") && endswith(prompt, " ? ")) {
|
|
|
+
|
|
|
+ if (last_offer != 0) percent -= 1.0;
|
|
|
+
|
|
|
+ if (buying)
|
|
|
+ last_offer = (int)(initial_offer * (100 - percent) / 100.0);
|
|
|
+ else
|
|
|
+ last_offer = (int)(initial_offer * (100 + percent) / 100.0);
|
|
|
+ BUGZ_LOG(fatal) << "Offer: " << last_offer << " % " << percent;
|
|
|
+ std::string text = std::to_string(last_offer);
|
|
|
+ text.append("\r");
|
|
|
+ to_server(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (at_command_prompt(prompt)) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (active_port == port[0])
|
|
|
+ active_port = port[1];
|
|
|
+ else
|
|
|
+ active_port = port[0];
|
|
|
+
|
|
|
+ std::string move = std::to_string(active_port);
|
|
|
+ to_client("Moving...\n\r");
|
|
|
+ move.append("\r");
|
|
|
+ to_server(move);
|
|
|
+
|
|
|
+ state = 2;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
void ScriptTrader::client_input(const std::string &cinput) { deactivate(); };
|