This commit is contained in:
Jeff 2024-07-08 19:06:41 -04:00
parent 746e2174e1
commit 43d08060c4
2 changed files with 15 additions and 35 deletions

View File

@ -19,7 +19,7 @@ orientation = "East"
"common.items.armor.misc.head.hare_hat" = 100_000 "common.items.armor.misc.head.hare_hat" = 100_000
"common.items.armor.misc.head.winged_coronet" = 20_000 "common.items.armor.misc.head.winged_coronet" = 20_000
"common.items.consumable.potion_minor" = 150 "common.items.consumable.potion_minor" = 150_000_000
"common.items.glider.skullgrin" = 20_000 "common.items.glider.skullgrin" = 20_000

View File

@ -175,7 +175,7 @@ impl Bot {
.. ..
}) => { }) => {
if let Some(uid) = self.client.uid() { if let Some(uid) = self.client.uid() {
if uid == target && self.last_ouch.elapsed() > Duration::from_secs(2) { if uid == target && self.last_ouch.elapsed() > Duration::from_secs(1) {
self.client self.client
.send_command("say".to_string(), vec!["Ouch!".to_string()]); .send_command("say".to_string(), vec!["Ouch!".to_string()]);
@ -186,8 +186,8 @@ impl Bot {
VelorenEvent::Outcome(Outcome::HealthChange { info, .. }) => { VelorenEvent::Outcome(Outcome::HealthChange { info, .. }) => {
if let Some(uid) = self.client.uid() { if let Some(uid) = self.client.uid() {
if uid == info.target if uid == info.target
&& info.amount.is_sign_positive() && info.amount.is_sign_negative()
&& self.last_ouch.elapsed() > Duration::from_secs(2) && self.last_ouch.elapsed() > Duration::from_secs(1)
{ {
self.client self.client
.send_command("say".to_string(), vec!["That hurt!".to_string()]); .send_command("say".to_string(), vec!["That hurt!".to_string()]);
@ -196,12 +196,6 @@ impl Bot {
} }
} }
} }
VelorenEvent::Outcome(Outcome::Death { .. }) => {
self.client
.send_command("say".to_string(), vec!["Really?".to_string()]);
self.last_ouch = Instant::now();
}
VelorenEvent::TradeComplete { result, .. } => { VelorenEvent::TradeComplete { result, .. } => {
log::info!("Completed trade: {result:?}"); log::info!("Completed trade: {result:?}");
@ -240,6 +234,10 @@ impl Bot {
} }
fn handle_trade(&mut self, trade: PendingTrade) -> Result<(), String> { fn handle_trade(&mut self, trade: PendingTrade) -> Result<(), String> {
if trade.is_empty_trade() {
return Ok(());
}
let my_offer_index = trade let my_offer_index = trade
.which_party(self.client.uid().ok_or("Failed to get uid")?) .which_party(self.client.uid().ok_or("Failed to get uid")?)
.ok_or("Failed to get offer index")?; .ok_or("Failed to get offer index")?;
@ -266,10 +264,6 @@ impl Bot {
let their_coins = their_inventory let their_coins = their_inventory
.get_slot_of_item_by_def_id(&ItemDefinitionIdOwned::Simple(COINS.to_string())) .get_slot_of_item_by_def_id(&ItemDefinitionIdOwned::Simple(COINS.to_string()))
.ok_or("Failed to find coins")?; .ok_or("Failed to find coins")?;
let their_total_coin_amount = their_inventory
.get(their_coins)
.map(|item| item.amount() as i32)
.unwrap_or(0);
let (mut their_offered_coin_amount, mut my_offered_coin_amount) = (0, 0); let (mut their_offered_coin_amount, mut my_offered_coin_amount) = (0, 0);
let their_offered_items_value = let their_offered_items_value =
their_offer their_offer
@ -347,7 +341,6 @@ impl Bot {
for (slot_id, amount) in their_offer { for (slot_id, amount) in their_offer {
let item = their_inventory.get(*slot_id).ok_or("Failed to get item")?; let item = their_inventory.get(*slot_id).ok_or("Failed to get item")?;
let item_id = item.persistence_item_id(); let item_id = item.persistence_item_id();
if item_id == COINS { if item_id == COINS {
@ -395,20 +388,6 @@ impl Bot {
return Ok(()); return Ok(());
} }
if my_offered_items_value > their_total_coin_amount {
self.client.send_command(
"tell".to_string(),
vec![
self.find_name(&trade.parties[their_offer_index])
.ok_or("Failed to get uid")?
.to_string(),
format!("I need {my_offered_items_value} coins or trade value from you."),
],
);
return Ok(());
}
let difference = their_offered_items_value - my_offered_items_value; let difference = their_offered_items_value - my_offered_items_value;
// If the trade is balanced // If the trade is balanced
@ -416,6 +395,8 @@ impl Bot {
// Accept // Accept
self.client self.client
.perform_trade_action(TradeAction::Accept(trade.phase)); .perform_trade_action(TradeAction::Accept(trade.phase));
return Ok(());
// If they are offering more // If they are offering more
} else if difference.is_positive() { } else if difference.is_positive() {
// If they are offering coins // If they are offering coins
@ -532,14 +513,13 @@ impl Bot {
} }
fn handle_position_and_orientation(&mut self) -> Result<(), String> { fn handle_position_and_orientation(&mut self) -> Result<(), String> {
match self.client.position() { let current_position = self.client.current::<Pos>();
Some(current_position) => {
if current_position == self.position.into() { if let Some(current_position) = current_position {
if current_position.0 == self.position.into() {
return Ok(()); return Ok(());
} }
} }
None => return Ok(()),
}
let entity = self.client.entity(); let entity = self.client.entity();
let ecs = self.client.state_mut().ecs(); let ecs = self.client.state_mut().ecs();